SQL - replace zero values in a table with blank or null

Is there an easy way to change all the zero values
in a SQL table to blank or null and leave the positive or
negative values.

eg table_1 before

Field1      Field2
0      1
12      100
14      0
17      18
0      0
3      4      

eg table_1 after

Field1      Field2
      1
12      100
14      0
17      18

3      4

I am using Oracle SQL version 8.

Many Thanks,

Jason.
JasonAshAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TaconvinoCommented:
Update table_1 set Field1 = null where Field1 = 0

Update table_1 set Field2 = null where Field2 = 0

That should work...

+TCV
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_Gerry_Commented:
or do it in one update statement !

update table_1
set field1 = case field1 when 0 then null else field1 end,
     field2 = case field2 when 0 then null else field2 end
where field1=0 or field2=0
0
_Gerry_Commented:
oops, that was SqlServer T/SQL syntax - it might work on Oracle :-) If not similar struture/approach might work.
0
WelkinMazeCommented:
Hi there,

You can try one of these 3 ways:

With two separate queries:

UPDATE table_1 SET field1 = NULL WHERE field1 = 0;
UPDATE table_1 SET field2 = NULL WHERE field2 = 0;

or

With one shorter query if zero values prevail:

UPDATE table_1
SET field1 = DECODE (field1, 0, NULL, field1),
       field2 = DECODE (field2, 0, NULL, field2);

or

With one longer query if zero values are not too much:

UPDATE table_1
SET field1 = DECODE (field1, 0, NULL, field1),
       field2 = DECODE (field2, 0, NULL, field2)
WHERE field1 = 0 or field2 = 0;
0
JasonAshAuthor Commented:
Thanks all,

The code all worked but because Taconvino  was first out of the blocks heer gets the points.

Thanks J
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.