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: IF - exists -SQL syntax?

Re: IF - exists -SQL syntax?

From: <sybrandb_at_yahoo.com>
Date: 16 Jun 2006 03:31:12 -0700
Message-ID: <1150453872.158483.283800@u72g2000cwu.googlegroups.com>

Major wrote:
> I tried somethin like this (based on SQL-server scirpt):
>
> IF NOT EXISTS (select * from table_a where field_a='xxx' ) THEN
> INSERT INTO table_a.... ;
> END IF;
>
> What is a right way to do check that the row is not in the table?

either
a) not check it at all, and trap the DUP_VAL_ON_INDEX condition (assuming the column has an unique idex) b)
declare dummy varchar2(1)
begin
select 'x' into
from dual
where exists
(select 'x'
 from table_a where field_a='xxx'
)
exception
when no_data_found then
insert into table_a values....
end;
/

-- 
Sybrand Bakker
Senior Oracle DBA
Received on Fri Jun 16 2006 - 05:31:12 CDT

Original text of this message

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