Tuesday, 22 May 2012

Explain the DECODE function? Can it be used in the procedural statements? | PL SQL

  The DECODE function compares its first argument to one or more search expressions that are paired with result expressions. Any of the search or result expression can be null. If a search is successful, the corresponding result is returned.
No, the DECODE function cannot be used within the procedural statements. It can only be used within the SQL statements, as shown in the following code:
SELECT DECODE(emp_rating, NULL, 1500. 'C', 4000 'B', 6000, 'A', 8000)
INTO var_bonus FROM t_emp_rating WHERE emp_code = var_emp_code;

In the preceding code, if the emp_rating column is null, the DECODE function returns the value 1000.

No comments: