Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> update/insert in oracle
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