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!

Oracle Decode Help

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
Good day ..

Trying to use a simple decode statement on a number field.

Basically, I need to find out if the number field is greater or less than zero, and if it is greater than zero I would like to assign the value of one, if it is less than zero, than I would like to assign the value of -1. And I need this in my select statement.

Any help is much appreciated.
 
Actually you don't need to use decode for this. The function, sign(x), gives you +1 if x > 0 and -1 if x < 0. The only complication might be when x=0. Then sign(x)=0.

select sign(-5551),sign(789),sign(0) from dual

SIGN(-5551) SIGN(789) SIGN(0)
----------- ---------- ----------
-1 1 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top