luni, 22 decembrie 2014

Oracle SQL Select Case When

A lot of sql developers are wondering if:

• decode can evaluate a boolean expression
• there is any IIF function in Oracle SQL

Unfortunately, the answer is NO for both questions.
There is no SQL boolean type in Oracle. Just PL SQL.
There is no IIF function, either.

The solution is:

select Case When 1=2 Then 'YES' else 'NO' End from dual;

You can even select multiple columns without brackets.

select 1, Case When 1=1 Then 'YES' else 'NO' End from dual;

and, of course, you can evaluate table columns within.

Niciun comentariu:

Trimiteți un comentariu