最近 遇到一个很严重的问题,发现oracle case when 后面 只能接确定的值,我还是先举个例子吧: select
FId,
FName.
(case
when FUrl like '%club.csdn%' then '社区'
when FUrl like '%baidu%' then '摆渡'
when FUrl like '%google%' then 'google'
else FUrl
end) item from
table_urls
;在我的表table_urls里面有很多url,现在我想如果有匹配百度的url就将其都以"百度"这个名字显示,否则以原始url名字显示. 发现这个语句在mysql执行ok,但在oracle就报错,如果改成如下: select
FId,
FName.
(case
when FUrl like '%club.csdn%' then '社区'
when FUrl like '%baidu%' then '摆渡'
when FUrl like '%google%' then 'google'
else "其他URL"
end) item from
table_urls
;oracle执行ok!但不是我想要的结果,请问我应该如何达到我最上面那条SQL的需求!
FId,
FName.
(case
when instr(FUrl,'baidu',1,1)>0 '百度'
else "其他URL"
end) item
from
table_urls 这样不就实现了你的如果是baidu的话就 取值“百度”剩下的取值“其他URL”。
select
FId,
FName,--这里的句号改为逗号
(case
when FUrl like '%club.csdn%' then '社区'
when FUrl like '%baidu%' then '摆渡'
when FUrl like '%google%' then 'google'
else FUrl
end) item from
table_urls
--PL/SQL执行测试无压力
(CASE
WHEN NAME LIKE '%club.csdn%' THEN
'社区'
WHEN NAME LIKE '%baidu%' THEN
'摆渡'
ELSE
NAME
END) T_NAME
FROM xl_TEST;