Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: best way to conditionally insert a row
pascal.dulleck_at_veda.net wrote:
> 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
>
What do files have to do with inserts?
Are you aware of the MERGE statement?
http://www.psoug.org/reference/merge.html
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace x with u to respond) Puget Sound Oracle Users Group www.psoug.orgReceived on Fri Aug 10 2007 - 10:33:52 CDT