Oracle 9i Merge Command Problem

Posted on 2004-08-10
Last Modified: 2012-05-05
Hi I'm trying to use the merge command but have encountered a problem which does not seem to make sense. I am running the following code:

merge into dest
using src
on (dest.client_number = src.nclient)
when matched then
update set
dest.client_number = src.nclient
when not matched then
insert (dest.client_number)    

when trying to run it I get the following error:

ORA-00904: "DEST"."CLIENT_NUMBER": invalid identifier

Now this table exists and the user I am using is the owner of the table so I can't understand what's wrong. Any ideas?

The version of Oracle I am using is

Question by:Ktoshni
LVL 48

Accepted Solution

schwertner earned 500 total points
ID: 11770257
The cause is that you cannot update a column that has been referenced in the ON condition clause.

Restrictions on the update clause:  
   - You cannot specify DEFAULT when updating a view.  
   - You cannot update a column that has been referenced in the ON condition clause.
   - You cannot update the same row of the target table multiple times in the  same MERGE statement.
   - You must have INSERT and UPDATE object privileges on the target table  
     and SELECT privilege on the source table.
LVL 13

Expert Comment

ID: 11770262
It appears to be an undocumented restriction that you cannot UPDATE any column
you are MERGING on.

Here is example from,F4950_P8_CRITERIA:5318183934935,

MERGE INTO newemp n1
USING external_table e1
ON ( n1.empno = e1.empno )
    SET n1.empno    = e1.empno,
        n1.ename    = e1.ename,
        n1.job      = e1.job,    
        n1.mgr      = e1.mgr,
        n1.hiredate = e1.hiredate,
        n1.sal      = e1.sal,
        n1.comm     = e1.comm,
        n1.deptno   = e1.deptno
INSERT ( empno, ename, job, mgr, hiredate, sal, comm, deptno )
values ( e1.empno,
         e1.deptno )

ON ( n1.empno = e1.empno )
ERROR at line 3:
ORA-00904: "N1"."EMPNO": invalid identifier

ops$tkyte@ORA920.US.ORACLE.COM> MERGE INTO newemp  n1
  2  USING external_table e1
  3  ON ( n1.empno = e1.empno  )
  5      SET -- n1.empno   = e1.empno,
  6           n1.ename    = e1.ename,
  7           n1.job      = e1.job,
  8           n1.mgr      = e1.mgr,
  9           n1.hiredate = e1.hiredate,
 10           n1.sal      = e1.sal,
 11           n1.comm     = e1.comm,
 12           n1.deptno   = e1.deptno
 14  INSERT ( empno, ename, job, mgr, hiredate, sal, comm, deptno )
 15  values ( e1.empno,
 16           e1.ename,
 17           e1.job,
 18           e1.mgr,
 19           e1.hiredate,
 20           e1.sal,
 21           e1.comm,
 22           e1.deptno )
 23  /

LVL 48

Expert Comment

ID: 11770288
This is well documented prerequisite.
Also in 9.1 there is a bug, but it is known and you also use 9.2. So I think that we encounter the cause.
LVL 22

Expert Comment

by:earth man2
ID: 11770688
Your update statement is superfluous

dest.client_number is already equal to src.nclient

Author Comment

ID: 11770796
Thanks guys for the help! I'm awarding the points to schwertner since he pointed out the problem first but thanks to all for the unput.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle query output question 4 48
Select and Insert Query running slow 4 47
Oracle Verification of DataPump Export and Import 17 60
sum of columns in a row in oracle 3 33
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question