当前位置: 代码迷 >> Oracle技术 >> Oracle语句判断有关问题
  详细解决方案

Oracle语句判断有关问题

热度:77   发布时间:2016-04-24 08:17:16.0
Oracle语句判断问题

select a1,a2 from a,b  where a.a1=b.b1 

原始语句大致如上,现在我想在语句做一个判断,如果a1 is null,那么where后面就是a.a1=b.b1;如果a1 is not null,那么where后面就是a2 = b1。
求大神语句如何修改!!!

------解决方案--------------------
select a1,a2 from a,b where (a1 is null and a.a1=b.b1) or (a1 is not null and a.a2=b.b1)
------解决方案--------------------
select a1,a2 from a,b  where case when (a.a1 is null then a.a1 else a.a2 end)=b.b1 
------解决方案--------------------
引用:
select a1,a2 from a,b  where case when (a.a1 is null then a.a1 else a.a2 end)=b.b1


up
  相关解决方案