What will MySQL CHAR_LENGTH() function return if I provide NULL to it?


In this case, the output of CHAR_LENGTH() function depends on the condition that whether we are providing NULL as a string or we are providing simply NULL to it. Following example will demonstrate the difference −

mysql> Select CHAR_LENGTH(NULL);
+-------------------+
| CHAR_LENGTH(NULL) |
+-------------------+
| NULL              |
+-------------------+
1 row in set (0.00 sec)

mysql> Select CHAR_LENGTH('NULL');
+---------------------+
| CHAR_LENGTH('NULL') |
+---------------------+
| 4                   |
+---------------------+
1 row in set (0.00 sec)

As we can observe from the above result set that when we will provide NULL as a string, CHAR_LENGTH() function will return the number of characters i.e. 4, otherwise when we provide simply NULL then it returns NULL as output.

Updated on: 30-Jan-2020

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements