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


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.

Updated on: 20-Jun-2020

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements