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!

Conditional Select 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I found this SQL for SQL 7 and was looking for something similar in Oracle. I looked in the reference manuals and didn't come up with anything. I wanted to know if you knew of anything similar to it in Oracle. It basically conditionally sets a value based upon the value of another.


SELECT Flag = CASE WHEN ID =0 THEN 1 ELSE 0 END, id
FROM TableX
WHERE 0=0
 
No doubt this could be done using the decode function. However a direct calculation is possible:

select sign(-abs(id))+1 as flag, id
FROM TableX;
 

So is this how I do it?


SELECT DECODE (flag,0, '1','0') ,ID
FROM TableX
WHERE 0=0
 
More like
SELECT DECODE(id,0,'0',1,'1','NONE') FLAG, id FROM my_table;
 
I think the following would work

select decode(id,0,'1','0') as flag, id
FROM TableX;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top