我试图在select语句中编写case语句。由于height列是varchar2并且包含我需要消除字符的字符,如下所示:
SELECT FIRST_NAME,
LAST_NAME,
(CASE height
WHEN height LIKE '%>%' THEN -1
WHEN height LIKE '%<%' THEN -1
ELSE TO_NUMBER (height)
END) AS height
FROM TEMP;
我收到此Missing关键字错误。我是一个新手,如果有人能帮助我,我会很高兴。
答案 0 :(得分:1)
您搜索到的案例表达式的语法错误:
SELECT FIRST_NAME,
LAST_NAME,
(CASE
WHEN height LIKE '%>%' THEN -1
WHEN height LIKE '%<%' THEN -1
ELSE TO_NUMBER (height)
END) AS height
FROM TEMP
;
为了清楚起见,您可能希望合并产生相同代码的条件(当然,有用性取决于应用程序):
CASE WHEN height LIKE '%>%'
OR height LIKE '%<%'
THEN -1
ELSE TO_NUMBER (height)
END
使用正则表达式的变体(注意性能影响):
CASE WHEN REGEXP_LIKE ( height, '[<>]' )
THEN -1
ELSE TO_NUMBER (height)
END
答案 1 :(得分:0)
试试这个
SELECT FIRST_NAME,
LAST_NAME,
(CASE
WHEN height LIKE '%>%' THEN
-1
WHEN height LIKE '%<%' THEN
-1
ELSE
TO_NUMBER(height)
END) AS height
FROM TEMP;