0

Just wondering if there's a way of doing something like the below in Oracle, where if a returned result is one value you output one thing, else you output something else?

For example:

select if(COL1,1:'TRUE',0:'FALSE') from TABLE1;

Thanks in advance C

3
SQL> create table t1 (c1 number);

Table created.

SQL> insert into t1 values(1);

1 row created.

SQL> insert into t1 values(0);

1 row created.

SQL> commit;

Commit complete.

SQL> select decode(c1, 1, 'TRUE', 0, 'FALSE') from t1;

DECOD
-----
TRUE
FALSE
3

A CASE expression can also be used: https://docs.oracle.com/database/121/SQLRF/expressions004.htm#SQLRF20037

select case 
    when col1 =  1 
        then 'TRUE'
    when col1 = 0
        then 'FALSE'
    else
        'SOMETHING ELSE'
    end
from table1;

This is also a good discussion regarding DECODE and CASE: https://stackoverflow.com/questions/3193692/case-vs-decode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.