我做错了什么,我不断收到语法错误。
UPDATE common_lookup
SET common_lookup_column =
CASE
WHEN common_lookup_table = 'MEMBER' THEN
CASE
WHEN common_lookup_type IN ('INDIVIDUAL', 'GROUP') THEN
common_lookup_table || '_TYPE'
WHEN common_lookup_type LIKE '%CARD' THEN
'CREDIT_CARD_TYPE'
END
ELSE
common_lookup_table || '_TYPE'
END;
答案 0 :(得分:2)
在MySQL中,使用concat()
函数:
UPDATE common_lookup
SET common_lookup_column = (CASE WHEN common_lookup_table = 'MEMBER'
THEN (CASE WHEN common_lookup_type IN ('INDIVIDUAL', 'GROUP')
THEN concat(common_lookup_table, '_TYPE')
WHEN common_lookup_type LIKE '%CARD'
THEN 'CREDIT_CARD_TYPE'
END)
ELSE concat(common_lookup_table, '_TYPE')
END);
假设您打算没有来自内部NULL
的{{1}}值,您可以将此逻辑简化为:
case
操作UPDATE common_lookup
SET common_lookup_column = (CASE WHEN common_lookup_table = 'MEMBER' AND
common_lookup_type LIKE '%CARD'
THEN 'CREDIT_CARD_TYPE'
ELSE concat(common_lookup_table, '_TYPE')
END);
是几个数据库中的字符串连接运算符。