早教吧作业答案频道 -->数学-->
mysql的casewhen语句转oraclewhere子句条件如下:wherea.xxx='asdf'and(casewhen(b.ilike'%0%')thentruewhen(b.ilike'%1%')thenc.creatorCode=#code#when(b.ilike'%2%')then(d.createDept=#dept#and#flag#=1)elsefalseend)
题目详情
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.
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.
▼优质解答
答案和解析
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 -- (根据反回结果来过滤数据)
这是根据你提供的语句修改,给你提供一个参考吧:
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 -- (根据反回结果来过滤数据)
看了 mysql的casewhen...的网友还看了以下:
S J S Z T K D S M G Y C:W A N,Q B N G S N B Y G W 2020-04-06 …
(14)下列( )关键码序列不符合堆的定义。 A)B、C、E、G、H、M、P、Q、S、Y B)B、C 2020-05-23 …
y=ax2+bx+c顶点为(2,4)(1)用含a式子表示b,c(2)若y=kx+4(k不等于0)与 2020-07-25 …
谁能帮我组个英语单词①e、n、o、p、t、w、y②e③d、t、y④b、c、f、m、p、r、t、v⑤ 2020-07-29 …
设S为实数集R的非空子集,若对任意x,y∈S,都有x+y,x-y,xy∈S,则称S为封闭集,下列命 2020-07-29 …
设S、T是两个非空集合,且T真包含于S,S真包含于T,令X={x|x∈T且x不属于S},Y={y| 2020-08-01 …
类比“两角和与差的正余弦公式”的形式,对于给定的两个函数,S(x)=,C(x)=,其中a>0,且a 2020-08-03 …
类比两角和与差的正弦,余弦公式,对于给定的两个函数S(X)=(E^X-E^-X)/2,C(X)=( 2020-08-03 …
y''+y'+y=0作拉氏变换,(s^2+s+1)L(y)=0特征方程:s^2+s+1=0为什么是y 2020-11-08 …
急用我在备课这题难住了步设数集S={a,b,c,d}满足下列两个条件:(1)任意x,y∈S,xy∈S 2020-11-28 …