Case and decode

Can anyone help with a simple example of converting one from other like CASE to DECODE or DECODE to CASE.

Showing Answers 1 - 0 of 0 Answers

Both CASE and DECODE function as IF-THEN-ELSE statements:
(limit your conversions to SQL statements in Oracle only)

CASE
WHEN THEN

ELSE

END

converts to:

DECODE(, , , )

and

DECODE(, , , , , )

converts to:

CASE
WHEN THEN

WHEN THEN

ELSE

END

  Was this answer useful?  Yes

Sorry about that seems some of the info got stripped out of my examples, so once again:

CASE "expression"
WHEN "search condition 1" THEN
"return value 1"
ELSE
"return else value"
END

converts to:

DECODE("expression", "search condition 1", "return value 1", "return else value")

and

DECODE("expression", "search condition 1", "return value 1", "search condition 2", "return value 2", "return else value")

converts to:

CASE "expression"
WHEN "search condition 1" THEN
"return value 1"
WHEN "search condition 2" THEN
"return value 2"
ELSE
"return else value"
END

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions