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

MySQLMySQLi Database

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.

raja
Published on 19-Feb-2018 13:36:12
Advertisements