Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> update/insert in oracle

update/insert in oracle

From: Cobra__77 <Cobra__77_at_hotmail.com>
Date: Mon, 14 Aug 2000 13:00:10 GMT
Message-ID: <u3Sl5.792$Xg.6879@news-server.bigpond.net.au>

I have the following query

insert into mytab(x,y,val) select x,y,sum(val) from otherTab group by x,y

where x and y is my primary keys (ie compsite key)

It works fine sometimes...but now it crashes...because I may already have some rows in mytab with x and y....ie I get primary key violations.....and the insert fails.....

Is there a way in sql or pl sql to say....if x and y row exist then update the val column in otherTab to be
otherTab.val = otherTab.val + mytab.val
and if x and y does not exist ....it means it is a new row so we do a new row insert.....

Basically it means.....we do an insert or an update depending on primary keys existance in the myTab table......

any suggesions....
Thanks Received on Mon Aug 14 2000 - 08:00:10 CDT

Original text of this message

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