MySQL中的IF语句触发器

时间:2015-05-12 09:43:54

标签: mysql if-statement triggers

这是MySQL触发器中的查询代码。

if 1=2 then
    select 'Yes';
else
    select 'No';
end if;

但是有以下错误:

if '1'='2' then    select 'Yes' Error Code: 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 '1'='2' then    select 'Yes'' at line 1 0.000 sec

解决方案是什么?

1 个答案:

答案 0 :(得分:0)

在MySQL中,If语句的正确语法是

IF (Expression) THEN
               body;
ELSE
           body;
END IF;

另外,1=2不是表达式 它必须是某些条件,例如var>1var<2