无法理解案例陈述

时间:2013-04-22 23:45:57

标签: mysql

我有一个类似的案例陈述:

CASE
  WHEN purpose = "" THEN SET @sPurpose = "%%"
  WHEN purpose IS NULL THEN SET @sPurpose = "%%"
  ELSE SET @sPurpose = concat("%",purpose,"%");
END;

但是当我尝试编译该过程时,它会抛出此错误:

SQL Error: 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 
'WHEN purpose IS NULL THEN SET @sPurpose = "%%" ELSE SET @sPurpose = co' at line 13

我只是缺少一些语法上的东西吗?

1 个答案:

答案 0 :(得分:4)

这是正确的方法,

SET @sPurpose = CASE
                     WHEN purpose = "" THEN  "%%"
                     WHEN purpose IS NULL THEN  "%%"
                     ELSE  concat("%",purpose,"%")
                END;