what is wrong with this query.
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: what is wrong with this query.

  1. #1
    Join Date
    Apr 2005
    Location
    Saudi Arabia
    Posts
    13

    what is wrong with this query.

    WHAT IS THE PROBLEM WITH THIS QUERY . WHERE I AM MAKING MISTAKE.
    ANY BODY CAN HELP ME.


    MERGE into copy_emp AS c
    USING emp e
    ON (c.empno = e.empno)
    WHEN MATCHED THEN
    UPDATE SET
    c.empno = e.empno,
    c.ename = e.ename,
    c.job = e.job,
    c.mgr = e.mgr,
    c.hiredate = e.hiredate,
    c.sal = e.sal,
    c.comm = e.comm,
    c.deptno = e.deptno
    WHEN NOT MATCHED THEN
    insert values (e.empno,e.name,e.job,e.mgr,e.hiredate,e.sal,e.comm,e.deptno);

    WHEN I AM GOING TO RUN THIS CODE THE FOLLOWING ERROR ARAISE.

    SQL> /
    MERGE into copy_emp AS c
    *
    ERROR at line 1:
    ORA-02012: missing USING keyword

    THANKS
    SOHAIL

  2. #2
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    3,999

    Re: what is wrong with this query.

    Have you tried removing the 'AS'?

    Code:
    MERGE INTO copy_emp c USING  emp e
       ON (c.empno = e.empno)
     WHEN MATCHED THEN
    UPDATE SET c.empno      = e.empno,
               c.ename      = e.ename,
               c.job        = e.job,
               c.mgr        = e.mgr,
               c.hiredate   = e.hiredate,
               c.sal        = e.sal,
               c.comm       = e.comm,
               c.deptno     = e.deptno
    WHEN NOT MATCHED THEN INSERT VALUES
       ( e.empno,    e.name, e.job,  e.mgr,
         e.hiredate, e.sal,  e.comm, e.deptno);
    this space intentionally left blank

  3. #3
    Join Date
    May 2005
    Posts
    31
    also remove updating the column on which join is made othewise merge will throw an error i.e.

    MERGE INTO copy_emp c USING emp e
    ON (c.empno = e.empno)
    WHEN MATCHED THEN
    UPDATE SET --- c.empno = e.empno,
    c.ename = e.ename,
    c.job = e.job,
    c.mgr = e.mgr,
    c.hiredate = e.hiredate,
    c.sal = e.sal,
    c.comm = e.comm,
    c.deptno = e.deptno
    WHEN NOT MATCHED THEN INSERT VALUES
    ( e.empno, e.name, e.job, e.mgr,
    e.hiredate, e.sal, e.comm, e.deptno);
    Experience is a hard teacher because she gives the test first, the lesson afterwards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width