oracle 在 case 语句中返回一个布尔值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26971453/
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-19 02:37:38  来源:igfitidea点击:

Returning a boolean value in a case statement

oracleplsql

提问by M.K.

I am trying to return a boolean value from a case statement but the compiler is complaining about a ORA-00936: missing expression error:

我试图从 case 语句返回一个布尔值,但编译器抱怨 ORA-00936: missing expression 错误:

SELECT
  CASE MYCOLUMN
     WHEN NULL THEN  true
  ELSE
       false
  END,
FROM MYTABLE;

I also tried the following but it doesn't work:

我也尝试了以下但它不起作用:

SELECT
  CASE MYCOLUMN
     WHEN NULL THEN  SELECT true
  ELSE
       SELECT false
  END,
FROM MYTABLE;

Is it possible to do this?

是否有可能做到这一点?

回答by juergen d

You need the ISoperator for NULLchecks

您需要IS操作员进行NULL检查

SELECT CASE WHEN MYCOLUMN IS NULL
            THEN 1
            ELSE 0
       END
FROM MYTABLE;

回答by Rusty

BOOLEANtype is not supported in SQL. It is supported only in procedural PL/SQL

BOOLEANSQL 中不支持类型。它仅在过程 PL/SQL 中受支持