Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用起始位置为0的子字符串的SQL查询不会引发错误_Mysql_Sql_Xampp - Fatal编程技术网

Mysql 使用起始位置为0的子字符串的SQL查询不会引发错误

Mysql 使用起始位置为0的子字符串的SQL查询不会引发错误,mysql,sql,xampp,Mysql,Sql,Xampp,当我运行以下查询时: SELECT SUBSTRING(first_name,2,3) FROM customers; 如果名字是David,则返回“avi” 所以当我尝试时: SELECT SUBSTRING(first_name,0,3) FROM customers; 它返回null。(要查看,请单击下面的驱动器链接) 我不明白为什么输出为null而不是error。您需要写: select substring(first_name,1,3) from customers; 这应该与

当我运行以下查询时:

SELECT SUBSTRING(first_name,2,3) FROM customers;
如果名字是David,则返回“avi”

所以当我尝试时:

SELECT SUBSTRING(first_name,0,3) FROM customers;
它返回null。(要查看,请单击下面的驱动器链接)

我不明白为什么输出为null而不是error。

您需要写:

select substring(first_name,1,3) from customers;

这应该与xampp中的函数相同,xampp将1视为起始字符,而不是0。

对不起,没有人会单击链接的图像。请试着用几句话来解释你的问题-这样你有时甚至可以找到解决方案:)如果它不是以零开始的,那么为什么它不会抛出一个错误,说消息是从一开始使用的,而不是从零开始使用的?要提取子字符串的字符串中第一个字符的位置被认为是1。如果它为0,则它不会返回空值,而只返回空值。这可能是Mysql中定义此函数的方式。是的,如果len小于1,则结果将是空字符串。