Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning a boolean value in a case statement

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

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?


2 Answers

You need the IS operator for NULL checks

SELECT CASE WHEN MYCOLUMN IS NULL
            THEN 1
            ELSE 0
       END
FROM MYTABLE;
like image 179
juergen d Avatar answered Jul 04 '26 07:07

juergen d


BOOLEAN type is not supported in SQL. It is supported only in procedural PL/SQL

like image 36
Rusty Avatar answered Jul 04 '26 08:07

Rusty