Previous |
Next |
The DECODE
function compares a value or expression to search values, and returns a result when it finds a match. If a match is not found, then DECODE
returns the default value, or NULL
(if a default value is not specified).
The query in the following example uses the DECODE
function to show proposed salary increases for three different jobs.
Using the DECODE Function in a Query
SELECT LAST_NAME, JOB_ID, SALARY, DECODE(JOB_ID, 'PU_CLERK', SALARY * 1.10, 'SH_CLERK', SALARY * 1.15, 'ST_CLERK', SALARY * 1.20, SALARY) "Proposed Salary" FROM EMPLOYEES WHERE JOB_ID LIKE '%_CLERK' AND LAST_NAME < 'E' ORDER BY LAST_NAME;
Result:
LAST_NAME JOB_ID SALARY Proposed Salary ------------------------- ---------- ---------- --------------- Atkinson ST_CLERK 2800 3360 Baida PU_CLERK 2900 3190 Bell SH_CLERK 4000 4600 Bissot ST_CLERK 3300 3960 Bull SH_CLERK 4100 4715 Cabrio SH_CLERK 3000 3450 Chung SH_CLERK 3800 4370 Colmenares PU_CLERK 2500 2750 Davies ST_CLERK 3100 3720 Dellinger SH_CLERK 3400 3910 Dilly SH_CLERK 3600 4140 11 rows selected.