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: <pascal.dulleck_at_veda.net>
Date: Fri, 10 Aug 2007 01:09:54 -0700
Message-ID: <1186733394.061706.250760@z24g2000prh.googlegroups.com>


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

Original text of this message

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