where子句PL / SQL中的案例表达

魔法

如何在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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章