insert and update in single query [message #232952] |
Tue, 24 April 2007 04:29 |
ammishra
Messages: 179 Registered: January 2007 Location: india
|
Senior Member |
|
|
Hi,
I just want to confirm that there is any way in oracle 9i which I can insert or update the record on table in single query like ‘MERGE’ statement in oracle 9i..
--Yash
|
|
|
|
Re: insert and update in single query [message #232957 is a reply to message #232953] |
Tue, 24 April 2007 04:37 |
ammishra
Messages: 179 Registered: January 2007 Location: india
|
Senior Member |
|
|
Sorry Michel !! i did not get you ...
Actually we have scheduled cronjob in unix server which update every night employee table in my project. so my Perl script which getting data from ldap server it checks first employee id is exit or not that bases if else block update or insert the ldap record
In employee table so i am asking there is any way i can merge both if and else block queries in single query..
--Yash
|
|
|
|
Re: insert and update in single query [message #232973 is a reply to message #232958] |
Tue, 24 April 2007 05:52 |
ammishra
Messages: 179 Registered: January 2007 Location: india
|
Senior Member |
|
|
Michel,
I am asking sql and pl/sql question only, might be I am not asking in right manner Sorry for that…
I am takeing data from LDAP and inserting in oracle ..so my question is based on insert andUpdate in oracle ..let say I got following data from ldap
100,’xxx’……
Now I want to check 100 is exist in employee table or not .. let say I used following dummy
Select count(*) into flag from employee where employee_id=100
If flag=1 then
Update employee
Else
Insert employee
End if;
I am trying to wrote the query for the above logic is as:
MERGE INTO employee a
USING employee b
ON ( b.employee_id=a.employee_id and b.employee_id=100)
WHEN MATCHED THEN
UPDATE SET a.last_name = 'abc'
WHEN NOT MATCHED THEN
INSERT (last_name ,employee_id,email,job_id )
VALUES ('xxxxx' ,100,'xxx','AD_PRES')
But I was suppose that query should insert one record but it has inserted 21 times to same record
Can u suggest how I get the solution ..
--Yash
|
|
|
|
|
|