MYSQL没用过,不过我想case when then应该也是支持的吧: SELECT (CASE length(POPEDOM) WHEN 3 THEN substr(POPEDOM, 0, 2) WHEN 4 THEN substr(POPEDOM, 0, 3) WHEN 5 THEN substr(POPEDOM, 0, 2) WHEN 6 THEN substr(POPEDOM, 0, 3) WHEN 7 THEN substr(POPEDOM, 0, 2) END) AS TYPE FROM DUAL;
SELECT (CASE length(POPEDOM)
WHEN 3 THEN
substr(POPEDOM, 0, 2)
WHEN 4 THEN
substr(POPEDOM, 0, 3)
WHEN 5 THEN
substr(POPEDOM, 0, 2)
WHEN 6 THEN
substr(POPEDOM, 0, 3)
WHEN 7 THEN
substr(POPEDOM, 0, 2)
END) AS TYPE
FROM DUAL;
oracle的decode()和case when功能上应该是一样的。