0

我正在尝试IF与内部的其他代码一起使用MySql stored procedure,但事情似乎并不顺利,我无法保存存储过程。如果我删除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
4

2 回答 2

2

尝试这个:

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
)
于 2013-09-17T09:56:36.913 回答
1

使用案例

    SET ret_val = CASE this_id
    WHEN 1 THEN CONCAT (
        'Blue Type 1',
        'Blue Type 2',
        'Blue Type 3', 
            case when FIND_IN_SET (10,vals) THEN
                'Grey Link'
            ELSE
                'Blue link'
            END
        )
于 2013-09-17T09:57:46.440 回答