Re: PL/SQL Update and Insert into Table using a lookup

From: David Burger <dburger213_at_fuse.net>
Date: Tue, 20 May 2003 21:30:50 -0400
Message-ID: <3ecad6ca$1$70222$a04e5680_at_nnrp.fuse.net>


There are some default cursor variables that you can use. %ROWCOUNT tells you how many rows were updated with the last update statement. This method would be preferable, as a general rule, if there were more rows to be updated than to be inserted.

Update table
set col1 = val1,

     col2 = val2,
     col3 = val3

where column = key;

If SQL%ROWCOUNT = 0 THEN

   Insert into table (col1, col2, col3, ...)    VALUE (val1, val2, val3, ...);
END IF;

-- 

Thanks,
Dave Burger
"Mark Regan" <mark.regan_at_bskyb.com> wrote in message
news:c00c1cf6.0305150210.290ce007_at_posting.google.com...

> Hi,
>
> I am relatively new to PL/SQL and am trying to create a script that
> will update a table with new records from another table or insert the
> record if no record currently exists. The records contain a unique
> identifier that will be used to check if the record already exists on
> the table.
>
> However the unique identifier does not have an index built on it on
> this table.
>
> Any ideas how I would write this?
>
> Thanks
Received on Wed May 21 2003 - 03:30:50 CEST

Original text of this message