Bug #18807 Undeclared variables are set to empty string, not NULL.
Submitted: 5 Apr 2006 14:19 Modified: 14 Apr 2006 8:51
Reporter: Tobias Asplund Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.21-BK, 5.0.19 OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[5 Apr 2006 14:19] Tobias Asplund
Description:
If you refer to a variable that has not been initialized, it has a value of NULL and a type of string. (From the manual)

In 5.1 (and < 5.0 versions)
eeyore> SELECT @akdfad;
+---------+
| @akdfad |
+---------+
| NULL    |
+---------+
1 row in set (0.00 sec)

On 5.0:
mysql> SELECT @blah;
+-------+
| @blah |
+-------+
|       |
+-------+
1 row in set (0.10 sec)

How to repeat:
SELECT @asdlkfjalskdjflaksdjflakjdlkfasd;
[5 Apr 2006 14:35] Tobias Asplund
mysql> SELECT IFNULL(@asdfasdfasdfdad, 'no value');
+--------------------------------------+
| IFNULL(@asdfasdfasdfdad, 'no value') |
+--------------------------------------+
| no value                             |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT @asdfasdfasdfdad;
+------------------+
| @asdfasdfasdfdad |
+------------------+
|                  |
+------------------+
1 row in set (0.00 sec)

Seems like it is NULL, but doesn't display like it would be.......
[5 Apr 2006 14:42] Valeriy Kravchuk
Verified just as described on Linux with 5.0.21-BK (ChangeSet@1.2135, 2006-04-04 15:40:42+05:00).
[11 Apr 2006 12:02] Tobias Asplund
mysql> SELECT CONCAT(NULL);
+--------------+
| CONCAT(NULL) |
+--------------+
|              |
+--------------+
1 row in set (0.00 sec)

Seems to suffer from the same problem.
[12 Apr 2006 13:11] Tobias Asplund
Most likely a duplicate of #18813 - since it displays the same behaviour.
[14 Apr 2006 8:51] Valeriy Kravchuk
Duplicate of bug #18813 (that is marked as a duplicate of another one, not sure why...). Maybe, because it fixed with the same bug fix.