Oracle MERGE Statement Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rashmi
    New Member
    • Nov 2005
    • 1

    #1

    Oracle MERGE Statement Error

    Code:
     
    CREATE TABLE MERGE1 ( ID NUMBER(5),NAME VARCHAR2(25));
      
    CREATE TABLE MERGE2 ( ID NUMBER(5),NAME VARCHAR2(25) ) ;
     
    create or replace procedure merge_upsert
    as
    BEGIN
    MERGE INTO merge1 a USING merge2 b
    ON (a.tid=b.tid)
    WHEN MATCHED THEN
    UPDATE
    SET a.name=b.name,
    WHEN NOT MATCHED THEN
    INSERT VALUES(b.tid+1,b.name);
    commit;
    END;
    /
    I get the following error when I execute the procedure:

    BEGIN [color=black]merge_upsert; END;[/color]
    [color=darkred][/color]
    [color=darkred]*[/color]
    [color=darkred]ERROR at line 1:[/color]
    [color=darkred]ORA-00904: "A"."TID": invalid identifier[/color]
    [color=darkred]ORA-06512: at "STAGE5.MERGE_U PSERT", line 4[/color]
    [color=darkred]ORA-06512: at line 1[/color]

    Now this is something which I am not able the reason out for the error

    Kindly give me an explanation of this if any of you have already worked on this
    Looking for your quick reply
    Regards
    Rashmi Ranjan
    Last edited by Niheel; Nov 18 '05, 07:46 AM.
  • Altasen.com
    New Member
    • Nov 2005
    • 8

    #2
    Hi Rashmi,

    this is a typo: in the line:
    ON (a.tid=b.tid)
    it should be: ON (a.id=b.id)
    And also in the insert-statement.

    HTH,
    Qui,
    More info on http://www.altasen.com

    Comment

    Working...