English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The choice depends on the database. In ORACLE database, an empty string will be converted to NULL.
In MySQL, it is better to use an empty string than NULL. It is easy to check the length of an empty string in some boundary conditions, while it is not possible to use NULL. To find NULL, we need to add an additional condition, that is, 'IS NULL'
We can check that the length of NULL is 0, while the length of an empty string is1.
To check the length of NULL.
mysql>SELECT count(NULL);
Here is the output of the above query.
+-----------------+ | count(NULL) | +-----------------+ | 0 | +-----------------+ 1 row in set (0.05 sec)
Therefore, the length of NULL in MySQL is 0.
Check the length of an empty string.
mysql>SELECT count('');
Here is the output.
+-----------+ | count('') | +-----------+ | 1 | +-----------+ 1 row in set (0.00 sec)
It displays the length of an empty string as1.