Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: update/insert in oracle
I think you must use 2 statement 1 for updating exeist x and y, and other for insert new x and y
In article <u3Sl5.792$Xg.6879_at_news-server.bigpond.net.au>,
"Cobra__77" <Cobra__77_at_hotmail.com> wrote:
> 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
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Mon Aug 14 2000 - 08:59:21 CDT
![]() |
![]() |