Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: IF - exists -SQL syntax?
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 DBAReceived on Fri Jun 16 2006 - 05:31:12 CDT