我怎样才能在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')值显然是错误的,在运算符中, 但我无法弄清楚如何匹配正确的语法。
谢谢!
答案 0 :(得分:4)
您通常希望使用简单的布尔逻辑,而不是在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
条件是否旨在为逻辑添加任何内容。