GeekInterview.com
Series: Subject: Topic:
Question: 8 of 190

Case and decode

can anyone help with a simple example of converting one from other like CASE to DECODE or DECODE to CASE.
Asked by: Interview Candidate | Asked on: Oct 11th, 2011
Showing Answers 1 - 2 of 2 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

  
Login to rate this answer.

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

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.