两个简单的 MySQL 语句导致语法错误
我很困惑。以下 MySQL 查询:
SET @a := 0;
SELECT *
FROM users;
给出错误:
无效查询:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 2 行“SELECT * FROM users”附近使用的正确语法`
当我切换语句的顺序时,我再次在第 2 行遇到相同的错误(即使我切换它们)
但是,任何一条线本身都运行良好。什么可能导致这种情况?
I'm confounded. The following MySQL query:
SET @a := 0;
SELECT *
FROM users;
Gives the error:
Invalid query: 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 'SELECT * FROM users' at line 2`
When I switch the order of the statements, I get the same error, again on line 2 (even though I switched them)
However, either line by themselves runs fine. What could possibly cause this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我打赌您正在尝试在 mysql_query() 中执行此查询(或任何编程语言中的一些类似函数),但它只接受单个查询。所以解决方案是将这个查询分成 2 个调用。
I bet you're trying to perform this query in the
mysql_query()
(or some similar function from any programming language), but it accepts only single query. So the solution is to split this queries into 2 calls.您可以在一个查询中完成此操作,如下所示:
技巧
,或者大胆地使用存储过程,这样它始终是一个调用:P
存储过程
PHP 脚本< /强>
you can do it in one query as follows:
The trick
or be adventerous and use a stored procedure so it's always a single call :P
Stored procedure
PHP script