Tuesday, March 28, 2023

Database - What is the use of Decode function in SQL?

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

Featured Post

OIC - Solution for 404 Not Found Error When Calling a Local Integration dynamically in OIC project

Issue: A 404 Not Found error occurs when dynamically calling a local integration within a project in OIC. Error details: CloudInvocationExc...