带有 OR 的 Oracle CASE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1099845/
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
Oracle CASE with OR
提问by Rob van Wijk
回答by akf
have you tried putting your OR statement in parens?
你有没有试过把你的 OR 语句放在括号中?
CASE WHEN (A > 0 OR B >0) THEN c=1 END;
回答by Rob van Wijk
You posted a CASE expression, but named it a CASE statement. That's probably where the confusion comes from. The CASE expression is valid:
您发布了一个 CASE 表达式,但将其命名为 CASE 语句。这可能是混乱的来源。CASE 表达式有效:
SQL> declare
2 bool boolean;
3 a int := 1;
4 b int := 0;
5 c int := 1;
6 begin
7 bool := CASE WHEN A > 0 OR B >0 THEN c=1 END;
8 if bool is null
9 then
10 dbms_output.put_line('NULL');
11 elsif bool
12 then
13 dbms_output.put_line('TRUE');
14 else
15 dbms_output.put_line('FALSE');
16 end if;
17 end;
18 /
TRUE
PL/SQL procedure successfully completed.
But you probably meant to use the CASE-statement, which ends with "END CASE" instead of "END". An example:
但是您可能打算使用以“END CASE”而不是“END”结尾的 CASE 语句。一个例子:
SQL> declare
2 a int := 1;
3 b int := 0;
4 c int;
5 begin
6 case
7 when a > 0 or b > 0 then
8 c := 1;
9 end case
10 ;
11 dbms_output.put_line(c);
12 end;
13 /
1
PL/SQL procedure successfully completed.
Regards, Rob.
问候,罗布。