oracle PL/SQL 中 CASE 语句中的堆栈条件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/311184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:39:16  来源:igfitidea点击:

Stack conditions in CASE statement in PL/SQL

oracleplsql

提问by Xavier Poinas

I'm using Oracle 10g and I'm trying to "stack" the conditions in a CASE statement, like I would do in C++ :

我正在使用 Oracle 10g 并且我试图在 CASE 语句中“堆叠”条件,就像我在 C++ 中所做的那样:

case 1:
case 2:
    // instructions
    break;

i.e. having the same code block executed for two different successful conditions.

即在两个不同的成功条件下执行相同的代码块。

I've tried :

我试过了 :

WHEN 1, 2 THEN
WHEN 1 OR 2 THEN

... without luck. Is it even possible ?

...没有运气。甚至有可能吗?

EDIT- Full snippet

编辑- 完整片段

CASE v_n
  WHEN (1 OR 2) THEN
    dbms_output.put_line('Case 1 or 2');
  WHEN 3 THEN
    dbms_output.put_line('Case 3'); 
END CASE;

Generates an expression is of wrong typeerror

生成表达式错误类型错误

回答by WW.

You need to use this format:

您需要使用这种格式:

CASE
  WHEN v_n = 1 OR v_n = 2 THEN
    dbms_output.put_line('Case 1 or 2');
  WHEN v_n = 3 THEN
    dbms_output.put_line('Case 3'); 
END CASE;

回答by DKroot

It is possible to use IN just as in SQL:

可以像在 SQL 中一样使用 IN:

BEGIN
  CASE 
    WHEN EXTRACT(YEAR FROM SYSDATE) IN (2015, 2016, 2017) THEN
      dbms_output.put_line('Yes');
    ELSE
      dbms_output.put_line('No');
  END CASE;
END;
/