[英]mySQL SUBSTRING with multiple conditions in WHERE clause
I have this query: 我有这个问题:
SELECT DISTINCT phone, department
FROM `users`
WHERE ((SUBSTRING(phone,1,3) = '399')
AND (SUBSTRING(phone,5,4) BETWEEN '3400' AND '3499')
OR (SUBSTRING(phone,1,3) = '244')
AND (SUBSTRING (phone,5,4) BETWEEN '5400' AND '5499'))
that gives me this error: 这给了我这个错误:
#1630 - FUNCTION Database.SUBSTRING does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
The query works if I only use this: 如果我只使用此查询,则查询有效:
SELECT DISTINCT phone, department
FROM `users`
WHERE (SUBSTRING(phone,1,3) = '399')
AND (SUBSTRING(phone,5,4) BETWEEN '3400' AND '3499')
According to the MySQL Function Name Parsing there must be no whitespace between the built-In function name ('SUBSTRING' in your case) and the following “(” parenthesis character. It's a default parser behaviour to distinguish whether names of the built-in functions are being used as function calls or as identifiers in nonexpression context. 根据MySQL 函数名称解析 ,内置函数名称(在您的情况下为“SUBSTRING”)和下面的“(”括号字符)之间必须没有空格。这是一种默认的解析器行为,用于区分内置函数的名称函数被用作函数调用或非映射上下文中的标识符。
So if you remove the white space after 'SUBSTRING' function call in the last line, your query will work fine: 因此,如果您在最后一行的'SUBSTRING'函数调用后删除空格,您的查询将正常工作:
SELECT DISTINCT phone, department
FROM `users`
WHERE ((SUBSTRING(phone,1,3) = '399')
AND (SUBSTRING(phone,5,4) BETWEEN '3400' AND '3499')
OR (SUBSTRING(phone,1,3) = '244')
AND (SUBSTRING(phone,5,4) BETWEEN '5400' AND '5499'))
SUBSTRING和(。)之间没有空格。如果你真的想要,有一个db选项允许它。
You've got an extra space in the final clause: 你在最后一个条款中有一个额外的空间:
AND (SUBSTRING (phone,5,4) BETWEEN '5400' AND '5499'))
^---here
remove that, and the whole query will work. 删除它,整个查询将工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.