Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: best way to conditionally insert a row
I've had a similar problem two weeks ago. I wanted to copy all data
from one file to another, but let the existing rows in the target file
stay unchanged. To do this with one INSERT ... SELECT statement, I
found the following solution. (I haven't tried it in Oracle yet, but
it works fine in MS SQL Server)
insert into target (key1, key2, data1) select key1, key2, data1 from source where not exists (
select target.key1 from target where target.key1 = source.key1 and target.key2 = source.key2)
Greetings
Pascal
Received on Fri Aug 10 2007 - 03:09:54 CDT
![]() |
![]() |