Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain: decode? 1

Status
Not open for further replies.

00112233

Technical User
Aug 2, 2001
10
CA
Hello and thanks in advance:



Could anybody explain me this SQL statement?



------------------------------------------------

decode(e.domain,'SERV','LABOUR', 'PARTS') Domain

------------------------------------------------



It is my understanding that we should have another 'e.domain' just before the closing bracket. Then 'SERV' gets decoded into 'LABOUR' but what 'PARTS' get decode into?



If we want 'PARTS' to stay as is (I have looked at the data.... And it looks like so...) shouldn't this statement look like:



------------------------------------------------------

decode(e.domain,'SERV','LABOUR', 'PARTS', 'PARTS', e.domain) Domain

------------------------------------------------------



or better:



-------------------------------------------------

decode(e.domain,'SERV','LABOUR', e.domain) Domain

-------------------------------------------------



since we do not need to decode "PARTS' into anything?





Thanks for your help.











------------------------------------------------------------
Vancouver Education: find out about continuing education in Canada and Vancouver. Get program highlights and request more information. Free courses available!





Your Vancouver City Guide

- Your Vancouver Guide
 
The last parameter to decode will be used when no match is found.
i.e. if the column domain is not equal to 'SERV' the value 'PARTS' is returned.

Decode is non-standard. Use a case expression instead

Code:
case when e."DOMAIN" = 'SERV' then 'LABOUR'
   else 'PARTS' end as "DOMAIN"

Even Oracle supports it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top