title: Merge error in Oracle 11g
body: <p>I'm new at Oracle 11g and this forum. I just need to run a simple update statement using Oracle Merge statement because my SQL developer won't take it any other way.</p>
  
  <p>The strange thing is, no matter how I try correcting the statement, even after reading many entries in this forum I still got the exact same error messages.</p>
  
  <p>There are 2 different error messages, depend on how I run my statements in SQL Developer.  If I run my statement as a store procedure (the update statement is a small part within a store procedure. I commented out other SQL statements and just left this update   statement within the stored procedure) I got this error:</p>
  
  <h2> I ran this:</h2>
  
  <pre><code>create or replace
  PROCEDURE ADDR_UPDATE_2
  AS
  /*     other sql statements are commented out    */  
  
  MERGE INTO (SELECT id,xseq,line_1,line_2,zip,tax FROM ADDR ) b
  USING (SELECT id,xseq,line_1, line_2,NVL(zip, '') AS pos_10 , NVL(tax, '') AS pos_11
       FROM TEMP_ADDR ) v
  ON(b.id = v.id
    AND b.xseq = v.xseq)  
  WHEN MATCHED THEN UPDATE SET b.line_1 = v.line_1,
                            b.line_2 = v.line_2,                            
                            b.zip = v.pos_10,
                            b.tax = v.pos_11
                            WHERE b.line_1 &lt;&gt; v.line_1  
                            OR b.line_2 &lt;&gt; v.line_2
                            OR b.zip &lt;&gt; v.pos_10; 
  
  /*     other sql statements are commented out   */
  
  END;
  </code></pre>
  
  <h2>and I got this error:</h2>
  
  <p>Error(23,9): PLS-00103: Encountered the symbol "INTO" when expecting one of the following:     constant exception      table long double ref    char time timestamp interval date binary national character    nchar </p>
  
  <p>(I goggled everywhere and did not find any answer)</p>
  
  <p>line 23 refers to the word "INTO"</p>
  
  <ul>
  <li>But if I ran the above Merge statement by itself, NOT as part of a str. proc.,
  I don't get any error. I got a result: 0 rows merged.</li>
  </ul>
  
  <h2>Now I modified the Merge statement into:</h2>
  
  <pre><code>create or replace
  PROCEDURE ADDR_UPDATE_2
  AS
  
  /*  other sql statements are commented out  */  
  
  MERGE INTO ADDR b
  USING (SELECT id,xseq, line_1, line_2, NVL(zip, '') AS pos_10, 
              NVL(tax, '') AS pos_11 
       FROM TEMP_ADDR) v
   ON(b.id = v.id
      AND b.xseq = v.xseq
      AND b.line_1 &lt;&gt; v.line_1  
      OR b.line_2 &lt;&gt; v.line_2 
      OR  b.zip &lt;&gt; v.pos_10)  
   WHEN MATCHED THEN UPDATE SET b.line_1 = v.line_1,
                            b.line_2 = v.line_2,
                            b.zip = v.pos_10,
                            b.tax = v.pos_11;
  
   /*
     other sql statements are commented out
   */
  
  END;
  </code></pre>
  
  <h2>I got the same error:</h2>
  
  <p>Error(23,9): PLS-00103: Encountered the symbol "INTO" when expecting one of the following:     constant exception      table long double ref    char time timestamp interval date binary national character    nchar </p>
  
  <p>line 23 refers to the word "INTO"</p>
  
  <h2>When I ran the statement not as part of str. proc:</h2>
  
  <h2>I got a different error:</h2>
  
  <p>Error at Command Line:9 Column:8<br>
  Error report:
  SQL Error: ORA-38104: Columns referenced in the ON Clause cannot be updated: "B"."LINE_2"
  38104. 00000 -  "Columns referenced in the ON Clause cannot be updated: %s"
  *Cause:    LHS of UPDATE SET contains the columns referenced in the ON Clause
  *Action:</p>
  
  <p>I have tried looking for answer since 2 days ago with no result, is there anyone can help how to solve this problem?</p>