当前位置: > mysql的case when语句转oracle...
题目
mysql的case when语句转oracle
where子句条件如下:
where a.xxx = 'asdf' and (
case
when (b.i like '%0%') then true
when (b.i like '%1%') then c.creatorCode = #code#
when (b.i like '%2%') then (d.createDept = #dept# and #flag# = 1)
else false
end
)
这语句是改过,以免泄漏公司业务,只表示逻辑上是这个意思.
like让人有些无奈,b.i可以012都有,显然逻辑是如果有0,不管是否有1,2,用条件1判断,没有0,但有1,则用条件2,0,1都没有但有2,则用条件3.

提问时间:2020-11-08

答案
oracle也有case when的语法,照办就行,不过用在where条件中,需要有返回值的比较.
这是根据你提供的语句修改,给你提供一个参考吧:
where a.xxx = 'asdf' and (
case
when (b.i like '%0%') then true
when (b.i like '%1%') and c.creatorCode = #code# then true
when (b.i like '%2%') and (d.createDept = #dept# and #flag# = 1) then true
else false
end) = true
这是按照我的业务理解写的
where a.xxx = 'asdf' and (
case
when (b.i like '%0%') then 1
when (b.i like '%1%') and c.creatorCode = #code# then 2
when (b.i like '%2%') and (d.createDept = #dept# and #flag# = 1) then 3
else 4
end) = 1 -- (根据反回结果来过滤数据)
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.