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

Home -> Community -> Usenet -> c.d.o.tools -> Re: "insert or update" in one step?

Re: "insert or update" in one step?

From: Martin <m.suttrup_at_freenet.de>
Date: 31 May 2001 03:26:35 -0700
Message-ID: <d2a2bf74.0105310226.5c16c80b@posting.google.com>

"Spencer" <spencerp_at_swbell.net> wrote in message news:<aBhR6.139$fw1.191464_at_nnrp2.sbc.net>...
> the only way to an "update/insert" in a single call to the
> database is to use a pl/sql block (either anonymous or
> stored will work)
>
> you've got the idea though... select "for update" the row
> by key value. if found, update it, if not found, then insert.
>
> HTH
>
> "Todd" <gdulli_at_zdnetmail.edu> wrote in message
> news:3b159f56$0$1877_at_news.denver1.Level3.net...
> > Is there a way to do an "insert or update" statement in one step? i.e.
 I
> > want to insert a certain row if it's not there, or else just update it,
 without
> > doing a select first and then branching to either an insert or update.
> >
> > Thanks! - Todd (gdulli_at_zdnetmail.edu - change edu to com)
> >
> >
> >

Hi

if you're using a PL/SQL-Block than another way is BEGIN
   INSERT
EXCEPTION
   WHEN DUP_VAL_ON_INDEX THEN
      UPDATE
END; or

BEGIN
   UPDATE
   IF SQL%ROWCOUNT=0 THEN
      INSERT
   END IF;
END; If you are doing more Insert's use the first Block, else the second one.

HTH Martin Received on Thu May 31 2001 - 05:26:35 CDT

Original text of this message

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