What MySQL would return if we refer a user variable which is not assigned any value explicitly?

MySQLMySQLi Database

In case, when we refer a user variable which is not assigned any value explicitly, MySQL would return NULL. In other words, its value would be NULL. Following example would illustrate it −

mysql> Select @X, @Y, @Z, @S, @G;
+------+-------+----------+------+------+
| @X   | @Y    | @Z       | @S   | @G   |
+------+-------+----------+------+------+
| Ram  | Shyam | Students | 5000 | NULL |
+------+-------+----------+------+------+
1 row in set (0.00 sec)

We can see from the above result set that @X,@Y,@Z and @S has been assigned values explicitly and they returned the values but @G variable has not been assigned any value explicitly hence when we refer to it then MySQL returns NULL because it is having a NULL value.

raja
Published on 20-Feb-2018 15:16:55
Advertisements