Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Merge problem

Re: Merge problem

From: Bricklen <bricklen-rem_at_yahoo.comz>
Date: Wed, 20 Aug 2003 22:18:39 GMT
Message-ID: <3tS0b.638$K44.591@edtnps84>


Mohammad wrote:
> table used: 'emp' of "scott" schema
> i create a table "Jango" it's a copy of "emp" table and this table has no record
> i gave the following statment on 9i DB Server and fail to exc.
> Please tell me what's wrong in it
>
> MERGE INTO jango D
> USING ( SELECT empno,ename from emp ) e
> ON (d.empno = e.empno)
> WHEN MATCHED THEN UPDATE SET D.EMPNO = E.EMPNO, D.ENAME = E.ENAME
> WHEN NOT MATCHED THEN INSERT (D.EMPNO,D.ENAME)
> VALUES (E.EMPNO,E.ENAME)
>
>
> ERROR at line 3:
> ORA-00904: "D"."EMPNO": invalid identifier
>
> Thanks
> Mohammad

try it like:
  MERGE INTO jango D

     USING ( SELECT empno,ename from emp ) e
     ON (d.empno = e.empno)
     WHEN MATCHED THEN UPDATE SET D.ENAME = E.ENAME
    WHEN NOT MATCHED THEN INSERT (D.EMPNO,D.ENAME)
     VALUES (E.EMPNO,E.ENAME);

I believe it is because you cannot update the key that you are selecting   on (this may not work either, because you are also updating the ename). I'm not in a position to test this right now, though. Received on Wed Aug 20 2003 - 17:18:39 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US