DECODE function works similar to if-else statement or case statement. DECODE compares expression to each search value one by one and returns the result of that search which is equal to the expression. If there is no match than default value will get return.
SELECT EMPId,
DECODE (EMPId, 1, 'Delhi',
2, 'Texas',
3, 'London',
4, 'Mumbai',
'DefaultVal')
"Location" FROM Employee
WHERE Salary < 17000;
The above query will decode the value of EMPId and it will return Delhi if EMPId is 1 , if EMPId is 2 then it will return texas , if EMPId is 3 then it will return London, if EMPId is 4 it will return Mumbai otherwise it will return default value.
0 Comment(s)