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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL to convert 0 to NULL

Status
Not open for further replies.

MSIsam

Programmer
Sep 29, 2003
173
US
I am new to ORACLE syntax and need the SQL code to convert zero to NULL. I am used to Teradata that has a NULLIFZERO function.

Any help would be much appreciated,
Sam
 
Here's an example which may help

SELECT Keyfield,
CASE numberfield
WHEN 0 THEN NULL
ELSE numberfield
END
FROM tablename

-------------------------
The trouble with doing something right the first time is that noboby appreciates how difficult it was.
- Steven Wright
 
Sam,

Here is a tighter code alternative to John's fine suggestion:
Code:
SELECT KeyField, decode(numberfield,0,null,numberfield)
FROM tablename;

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 16:37 (03Sep04) UTC (aka "GMT" and "Zulu"), 09:37 (03Sep04) Mountain Time)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top