基於過濾器我想將其應用於要過濾的內容。基於變量的過濾器,如果變量中沒有值應用NO過濾器
例如,如果我有一個名爲p_filter的變量,可能具有值'A'或'B',我想根據它篩選特定的where子句。
SELECT *
FROM t1
WHERE
id NOT IN (select id from t2 WHERE t1.id = t2.id(+)) --only apply this filter if p_filter = 'A'
AND id NOT IN (select id from t3 WHERE t1.id = t3.id(+)) --only apply this filter if p_filter = 'B'
如果變量雖然爲空,我想爲它應用NO過濾器。我嘗試過這樣但它不起作用:
SELECT *
FROM t1
WHERE
CASE WHEN :p_filter != 'A' THEN 1 WHEN id NOT IN (select id from t2 WHERE t1.id = t2.id(+)) THEN 1 ELSE 0 END = 1
AND CASE WHEN :p_filter != 'B' THEN 1 WHEN id NOT IN (select id from t3 WHERE t1.id = t3.id(+)) THEN 1 ELSE 0 END = 1;
更新:我很愚蠢,我的意思是如果null應用沒有過濾器!
我很抱歉,我很愚蠢,我的意思是說,如果空應用沒有過濾器! – user2924127