2013-07-30 19 views
0

我有一個查詢,如下包括一個在SQL(Oracle)的動態條件

select -------- 
from table a 
left outer join ....c 
where 
(a.column='123') and (c.column='456') 

我想

包括 「(c.column = '456')」,只有當( c.column ='456')不爲空

如何在單個查詢中執行此操作?還是我需要編寫兩個單獨的查詢?

我試過(a.column = '123')和(c.column爲空),沒有工作

回答

3

嘗試:

select -------- 
from table a 
left outer join ....c 
where 
((a.column='123') and (c.column='456')) 
or c.column is not NULL 
0

嘗試把爲空的檢查和值456在同一套圓括號中:

select -------- 
from table a 
left outer join ....c 
where 
(a.column='123') and (c.column is not null and c.column='456')