Decode

•Work as IF-THEN-ELSE statement
•The decode function decodes expression after comparing it to each search value
•If the expression is the same as search, result is returned. If the default value is omitted, a null value is returned where a search value does not match any of the result values.

Select last_name, job_id, salary,
Decode(job_id, ‘IT_PROG’, 1.10*salary,
‘ST_CLERK’, 1.15*salary,
‘SA_REP’, 1.20*salary, salary) “New Salary”
From employees;




Select last_name, job_id, salary,
Case job_id
When 'IT_PROG' then salary*1.10
When 'ST_CLERK' then salary*1.15
When 'SA_REP' then salary*1.20
Else salary end "New Salary"
From employees;







0 comments:

Post a Comment