如何在PL / SQL中查询类似的内容?
declare
l_batch_type number := 1;
select
*
from table t
where
case
when l_batch_type = 1 then ('A', 'B')
when l_batch_type = 2 then ('C', 'D')
when l_batch_type = 3 then ('E', 'F')
when l_batch_type is null then null end in t.batch_type;
我收到SQL错误:ORA-00907:缺少右括号这显然与('X','Y')值和in运算符有关,但我不知道如何匹配正确的语法。
谢谢!
您通常希望使用简单的布尔逻辑,而不是将case
语句放在where
子句中
where (l_batch_type = 1 and t.batch_type in ('A', 'B'))
or (l_batch_type = 2 and t.batch_type in ('C', 'D'))
or (l_batch_type = 3 and t.batch_type in ('E', 'F'))
由于null
永远不会等于任何东西(也永远不会等于任何东西),所以我不确定您的l_batch_type is null
条件是否旨在向逻辑添加任何东西。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句