dbTalk Databases Forums  

question about merge

comp.databases.oracle.server comp.databases.oracle.server


Discuss question about merge in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
geos
 
Posts: n/a

Default question about merge - 10-25-2011 , 01:44 PM






I prepare a table as follows:

create table empm as select * from emp where deptno = 10;

then I merge more data this way:

merge into empm m
using emp e
on ( e.EMPNO = m.EMPNO )
when matched then
update set job='janitor' where ename='KING'
delete where job='janitor';

I check the result and 'KING the Janitor' is gone from empm table (as I
expected)

EMPNO ENAME JOB
---------- ---------- -------
7782 CLARK MANAGER
7934 MILLER CLERK

I rollback and make another merge, this time like this:

merge into empm m
using emp e
on ( e.EMPNO = m.EMPNO )
when matched then
update set job='janitor' where ename='KING'
delete where job='janitor'
when not matched then
insert (m.empno, m.ename, m.job)
values (e.empno, e.ename, e.job)
where e.deptno=20;

I check the result and see that 'KING the Janitor' is still there. I
expected the same behaviour as previously plus some guys from department 20.

EMPNO ENAME JOB
---------- ---------- ---------
7782 CLARK MANAGER
7839 KING janitor
7934 MILLER CLERK
7788 SCOTT ANALYST
7566 JONES MANAGER
7902 FORD ANALYST
7369 SMITH CLERK
7876 ADAMS CLERK

I checked out the manual for merge:

http://download.oracle.com/docs/cd/B...ments_9016.htm

but I don't see any reason for not removing janitor in the second
example. what's all about these additional inserts (or when not matched
clause) that makes oracle not to remove King the Janitor from the result
set in the second example?

I would greatly appreciate your explanation. I set Followup-To misc
group for this post so your answers will be directed there.

thank you,
geos

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.