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: best way to conditionally insert a row

Re: best way to conditionally insert a row

From: <vitalisman_at_gmail.com>
Date: Thu, 09 Aug 2007 08:44:26 -0700
Message-ID: <1186674266.585840.29790@19g2000hsx.googlegroups.com>


On 9 août, 02:05, Mark Harrison <m..._at_pixar.com> wrote:
> I would like to insert a row into a table, but only
> if the primary key does not exist.
>
> For example, if I have a table "keywords" with
> columns "name" and "val", I would like
>
> insert into keywords (name, val) values ('color', 'blue');
>
> to happen only if there is not already a row where
> name='color'.
>
> What is the best way to do this?
>
> Many TIA!
> Mark

What about the lazy way, by handling ORA-00001? PL/SQL exception DUP_VAL_ON_INDEX if you use PL/SQL here.

That's not really nice, but your code will be simpler in the end. Received on Thu Aug 09 2007 - 10:44:26 CDT

Original text of this message

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