我正在尝试将 IF
与 MySql
存储过程
中的其他代码一起使用,但事情似乎并不顺利,我无法保存存储过程。如果我删除 IF
一切正常并且我能够保存存储过程。
问题出在 IF
那里。你能帮忙吗?
错误
/* SQL Error (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 FIND_IN_SET (10,vals) THEN
'Grey Link'
ELSE
SET ret_val = 'Blue' at line 20 */
存储过程
BEGIN
DECLARE vals VARCHAR(2400);
DECLARE ret_val VARCHAR(2400);
select group_concat(elmAction) into vals from reports where id = this_id and userId = this_user;
SET ret_val = CASE this_id
WHEN 1 THEN CONCAT (
'Blue Type 1'
'Blue Type 2'
'Blue Type 3' #Here is where the problem is...
IF FIND_IN_SET (10,vals) THEN
'Grey Link'
ELSE
'Blue link'
END IF;
)
ELSE 'Error'
END;
RETURN (ret_val);
END
最佳答案
试试这个:
CONCAT (
'Blue Type 1',
'Blue Type 2',
'Blue Type 3',
IF( FIND_IN_SET (10,vals), 'Grey Link','Blue link')
)
使用 CASE
:
CONCAT (
'Blue Type 1',
'Blue Type 2',
'Blue Type 3',
CASE
WHEN FIND_IN_SET (10,vals) = 0 THEN 'Blue link'
WHEN FIND_IN_SET (10,vals) = 1 THEN ....
WHEN FIND_IN_SET (10,vals) = 2 THEN ....
ELSE
...
END
)
关于mysql - 在 MySql 存储过程中使用 IF 和 Concat 时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18846655/