In Oracle, Decode function allows us to add procedural if-then-else logic to the query. Decode compares the expression to each search value one by one, If expression is equal to a search, then the corresponding result is returned by the Oracle database. If a match is not found , then the default is returned.
Example:
Select bank_name, decode(bank_id l, 001, 'SBI', 002, 'ICICI',003,'Axis',Gateway) result from banks;
This above statement is equivalent to if-then-else statement as below:
IF bank_id = 001 THEN
result := 'SBI';
ELSIF bank_id = 002 THEN
result :='ICICI';
ELSIF bank_id =003 THEN
result := 'Axis';
ELSE
result := 'Gateway';
END IF
No comments:
Post a Comment