Home » SQL & PL/SQL » SQL & PL/SQL » Decode Query
Decode Query [message #594062] Fri, 23 August 2013 02:33 Go to next message
mist598
Messages: 854
Registered: February 2013
Location: Hyderabad
Senior Member
Hi all,

The below Decode query is


SELECT CASE deptno
WHEN 10 THEN 'ACCOUNTING'
WHEN 20 THEN 'RESEARCH'
WHEN 50 THEN 'SALES'
WHEN 30 THEN 'SALES'
ELSE 'Invalid'
END
FROM dept;


But my quetion is that, it prints WHEN 30 THEN 'SALES' after that it prints WHEN 50 THEN 'SALES' as 'Invalid'.

Why it prints like that can any explain me please..

Thanks&Regards,
Surya
Re: Decode Query [message #594064 is a reply to message #594062] Fri, 23 August 2013 02:41 Go to previous messageGo to next message
cookiemonster
Messages: 10846
Registered: September 2008
Location: Rainy Manchester
Senior Member
After 173 posts you should certainly know how to use [code] tags
So why haven't you?

If deptno is 50 then it will return SALES.
If you think differently then post an actual example of the query returning the wrong result. In code tags.
Re: Decode Query [message #594068 is a reply to message #594064] Fri, 23 August 2013 02:50 Go to previous messageGo to next message
mist598
Messages: 854
Registered: February 2013
Location: Hyderabad
Senior Member
Thanks for reply,

I used http://www.dpriver.com/pp/sqlformat.html(Instant SQL Formatter) again display like below format and sorry for that i made a mistake.

Regards,
Surya Smile
Re: Decode Query [message #594069 is a reply to message #594068] Fri, 23 August 2013 02:54 Go to previous messageGo to next message
Michel Cadot
Messages: 58605
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

Regards
Michel
Re: Decode Query [message #594070 is a reply to message #594062] Fri, 23 August 2013 02:55 Go to previous messageGo to next message
Michel Cadot
Messages: 58605
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
But my quetion is that, it prints WHEN 30 THEN 'SALES' after that it prints WHEN 50 THEN 'SALES' as 'Invalid'.


Your interpretation of the CASE statement is wrong.
Refer to the documentation: Database SQL Reference

Regards
Michel
Re: Decode Query [message #594073 is a reply to message #594070] Fri, 23 August 2013 02:59 Go to previous message
mist598
Messages: 854
Registered: February 2013
Location: Hyderabad
Senior Member
Thanks for suggest me Michel Cadot.. Smile
Previous Topic: Help: View of Item Hierarchy by Eliminating NULL Levels
Next Topic: How to Show only the address for The Yes Tax Reporting Site
Goto Forum:
  


Current Time: Mon Jul 28 15:49:56 CDT 2014

Total time taken to generate the page: 0.10218 seconds