“如果存在”的 SQL 语法
为什么我收到此错误:
#1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near
'IF EXISTS(SELECT id FROM mytable WHERE id = '1')' at line 1
我的 SQL 查询:
IF EXISTS(SELECT id FROM mytable WHERE id = '1')
谢谢。
Why I'm getting this error:
#1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near
'IF EXISTS(SELECT id FROM mytable WHERE id = '1')' at line 1
My SQL query:
IF EXISTS(SELECT id FROM mytable WHERE id = '1')
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
IF EXISTS
仅适用于存储过程。在存储过程之外,IF()
是一个带有 3 个参数的函数。正确的用法是IF EXISTS
only works in a stored procedure. Outside of a stored procedure,IF()
is a function which takes 3 arguments. Proper usage would be现在不在 MySQL 机器上,但看起来是这样,因为语句不完整,您需要告诉它如果 id 存在该怎么办。
IF EXISTS(...) 做某事
Not on a MySQL machine right now but it looks like its because the statement is incomplete, you need to tell it what to do if the id exists.
IF EXISTS(...) do something
IF EXISTS
在 MySQL 中没有任何意义。请参阅带有 EXISTS 或 NOT EXISTS 的子查询< /a> 有关用法的 MySQL 文档。
基本上,您需要在语句中使用它,而不仅仅是像逻辑块一样
IF EXISTS
doesn't make any sense in MySQL.See subqueries with EXISTS or NOT EXISTS in the MySQL documentation on usage.
Basically, you need to use it in a statement, and not just like a logical block
尝试使用
Try to use