Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Sql Update query syntax to increment a column containing nulls

Re: Sql Update query syntax to increment a column containing nulls

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 26 Mar 1999 13:39:37 GMT
Message-ID: <370c8dc0.10060686@192.86.155.100>


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  



Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Fri Mar 26 1999 - 07:39:37 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US