Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

MERGE using parameter variables

dbdanAug 29 2011 — edited Aug 29 2011
Hi All,

Can we use merge statement without using physical table as source? I will be passing all values as an input parameter to the procedure and the procedure will use merge statement by using input parameter. I am getting error when I run this test block.
Eg.
CREATE TABLE T1 (ID number(10), NAME VARCHAR2(10));
INSERT INTO T1 VALUES (1,'A');

DECLARE
    v1    number(10):=1;
    v2    varchar2(10):='B';
BEGIN
    MERGE INTO T1 d
    USING (select v1, v2 from dual) s
    ON (d.id = s.v1)
    WHEN MATCHED THEN
      UPDATE SET d.name = s.v2
    WHEN NOT MATCHED THEN
      INSERT (d.id, d.name)
      VALUES (s.v1, s.v2);
    dbms_output.put_line(sql%rowcount);
END;
Thanks,
Danish
This post has been answered by Kim Berg Hansen on Aug 29 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2011
Added on Aug 29 2011
5 comments
11,858 views