AI编程助手
AI免费问答

如果我将NULL提供给MySQL的CHAR_LENGTH()函数,它会返回什么?

WBOY   2023-08-23 16:54   1024浏览 转载

如果我将null提供给mysql的char_length()函数,它会返回什么?

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)

从上面的结果集中可以观察到,当我们将NULL作为字符串提供时,CHAR_LENGTH()函数将返回字符的数量,即4个字符,否则当我们仅提供NULL时,它将返回NULL作为输出。

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除