DECODE() allows you to perform if-then-else logic in SQL without having to use PL/SQL : Decode « PL SQL « Oracle PL / SQL






DECODE() allows you to perform if-then-else logic in SQL without having to use PL/SQL

SQL>
SQL> --Using the DECODE() Function
SQL>
SQL> --You use DECODE(value, search_value, result, default_value) to compare value with search_value. If the values are equal, DECODE() returns result, otherwise default_value is returned.
SQL>
SQL> --DECODE() allows you to perform if-then-else logic in SQL without having to use PL/SQL.
SQL>
SQL>
SQL> SELECT DECODE(1, 1, 2, 3)
  2  FROM dual;

DECODE(1,1,2,3)
---------------
              2

SQL>

           
       








Related examples in the same category

1.Use decode function to deal with NULL value
2.DECODE(x, search, result, default)
3.DECODE() to compare 1 to 2, and since they are not equal 3 is returned
4.If city equals 'New York', the string 'You are in New York' is returned, otherwise the string 'Not' is returned
5.Multiple search and result parameters to DECODE()