Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6320667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:00:57+00:00 2026-05-24T16:00:57+00:00

I have the following merge procedure. How can I access values from merge statement

  • 0

I have the following merge procedure. How can I access values from merge statement in exception handling part…

procedure merge_students
is 
begin
        merge into
              students a
            using
              studentstmp t
            on
              (a.code = t.code)
            when matched then update set a.name = t.name,

            when not matched then insert (code,name)
                                  values (t.code,t.name);
            EXCEPTION
                 WHEN DUP_VAL_ON_INDEX THEN
                    dbms_output.put_line('students code: ' || a.code); //how to access a.code here
                    dbms_output.put_line('studentsTMP code: ' || t.code); // and t.code here
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:00:57+00:00Added an answer on May 24, 2026 at 4:00 pm

    Depending on the Oracle version, you could use DML error logging. Something along the lines of

    Create the Source & Destination Tables with Data

    SQL> create table foo (
      2    col1 number primary key,
      3    col2 number unique
      4  );
    
    Table created.
    
    SQL> create table foo_temp (
      2    col1 number,
      3    col2 number
      4  );
    
    Table created.
    
    SQL> insert into foo values( 1, 1 );
    
    1 row created.
    
    SQL> insert into foo_temp values( 2, 1 );
    
    1 row created.
    
    SQL> insert into foo_temp values( 3, 2 );
    
    1 row created.
    

    Create the Error Log Table

    SQL> exec dbms_errlog.create_error_log( 'FOO' );
    
    PL/SQL procedure successfully completed.
    

    MERGE with the LOG ERRORS syntax

    Note that one row was sucessfully merged while one row generated a unique constraint exception and was written to the error table.

    SQL> merge into foo
      2    using foo_temp on (foo.col1 = foo_temp.col1)
      3   when matched then
      4      update set foo.col2 = foo_temp.col2
      5   when not matched then
      6      insert( col1, col2 )
      7        values( foo_temp.col1, foo_temp.col2 )
      8   log errors into err$_foo
      9   reject limit unlimited;
    
    1 row merged.
    
    SQL> select * from foo;
    
          COL1       COL2
    ---------- ----------
             1          1
             3          2
    
    SQL> select * from foo_temp;
    
          COL1       COL2
    ---------- ----------
             2          1
             3          2
    
    SQL> select * from err$_foo;
    
    ORA_ERR_NUMBER$
    ---------------
    ORA_ERR_MESG$
    --------------------------------------------------------------------------------
    
    ORA_ERR_ROWID$
    --------------------------------------------------------------------------------
    
    OR
    --
    ORA_ERR_TAG$
    --------------------------------------------------------------------------------
    
    COL1
    --------------------------------------------------------------------------------
    
    COL2
    --------------------------------------------------------------------------------
    
                  1
    ORA-00001: unique constraint (SCOTT.SYS_C0024443) violated
    
    I
    
    2
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have the following LINQ queries. How can I merge the two queries
I have the following Merge statement I'm working with: MERGE dbo.UnitOfMeasure AS target USING
I have the following two class functions which I'm attempting to merge into one
I have the following problem... I was trying to merge a remote branch into
I have the following 2 arrays that I'm trying to merge recursively so that
Is it possible to merge elements using XSLT. If I have the following XML
I have following LINQ statement: string[] str = { a, ab, abcd }; var
let's say I have the following config file [branch master] remote = origin merge
Hi I have a question about Batcher's odd-even-merge sort. I have the following code:
I am executing the following merge statement in SQL Server 2008: MERGE PopulationData AS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.