Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Sql Update query syntax to increment a column containing nulls
A copy of this was sent to "Global Infolinks" <me_at_nospam.com>
(if that email address didn't require changing)
On Fri, 26 Mar 1999 23:16:36 +1000, you wrote:
>I want to increment a column in a table. The column may be initially null.
>The following syntax doesnt work, because any arithmetic operation on null
>yields null :
> UPDATE MyTable SET Num = Num + 1;
>
update myTable set num = nvl(num,-1)+1;
that'll take NUM from NULL to ZERO....
or:
update mytable set num = decode( num, NULL, 0, num+1 )
>Is there a "Null to zero" function in Oracle Sql syntax.
>
>Thanks,
>Michael
>
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Service Industries
Reston, VA USA
--
http://govt.us.oracle.com/ -- downloadable utilities
![]() |
![]() |