set @var=1;
if @var>1 then
select * from client;
else
select * from otherTable;
end if;
这是我的 mysql 查询。你们能指出为什么显示错误吗? 这真是伤透我的脑筋了。
显示的错误是
IF @var >1 THEN SELECT *
FROM client;
MySQL said: Documentation
#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 @var>1 then
select * from client' at line 1
快速回答会非常有帮助。
最佳答案
在 MySQL 中,您必须在触发器或过程中执行它。
您不能只运行没有函数的脚本代码。
delimiter |
CREATE PROCEDURE simpleproc ()
BEGIN
set @var=1;
if @var>1 then
select * from client;
else
select * from otherTable;
end if;
END;
|
delimiter ;
之后你可以执行它
call simpleproc()
关于mysql - 简单的 IF.. Else.. mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18716425/