0

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

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

我只是错过了一些语法上的东西吗?

4

1 回答 1

4

这是正确的方法,

SET @sPurpose = CASE
                     WHEN purpose = "" THEN  "%%"
                     WHEN purpose IS NULL THEN  "%%"
                     ELSE  concat("%",purpose,"%")
                END;
于 2013-04-22T23:46:54.060 回答