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 6023925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:04:43+00:00 2026-05-23T04:04:43+00:00

I have an application that uses the Oracle MERGE INTO… DML statement to update

  • 0

I have an application that uses the Oracle MERGE INTO… DML statement to update table A to correspond with some of the changes in another table B (table A is a summary of selected parts of table B along with some other info). In a typical merge operation, 5-6 rows (out of 10’s of thousands) might be inserted in table B and 2-3 rows updated.

It turns out that the application is to be deployed in an environment that has a security policy on the target tables. The MERGE INTO… statement can’t be used with these tables (ORA-28132: Merge into syntax does not support security policies)

So we have to change the MERGE INTO… logic to use regular inserts and updates instead. Is this a problem anyone else has run into? Is there a best-practice pattern for converting the WHEN MATCHED/WHEN NOT MATCHED logic in the merge statement into INSERT and UPDATE statements? The merge is within a stored procedure, so it’s fine for the solution to use PL/SQL in addition to the DML if that is required.

  • 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-23T04:04:44+00:00Added an answer on May 23, 2026 at 4:04 am

    Another way to do this (other than Merge) would be using two sql statements one for insert and one for update. The “WHEN MATCHED” and “WHEN NOT MATCHED” can be handled using joins or “in” Clause.

    If you decide to take the below approach, it is better to run the update first (sine it only runs for the matching records) and then insert the non-Matching records. The Data sets would be the same either way, it just updates less number of records with the order below.

    Also, Similar to the Merge, this update statement updates the Name Column even if the names in Source and Target match. If you dont want that, add that condition to the where as well.

    create table src_table(
       id number primary key,
       name varchar2(20) not null
    );
    
    create table tgt_table(
       id number primary key,
       name varchar2(20) not null
    );
    
    insert into src_table values (1, 'abc');
    insert into src_table values (2, 'def');
    insert into src_table values (3, 'ghi');
    
    insert into tgt_table values (1, 'abc');
    insert into tgt_table values (2,'xyz');
    
    SQL> select * from Src_Table;
    
            ID NAME
    ---------- --------------------
             1 abc
             2 def
             3 ghi
    
    SQL> select * from Tgt_Table;
    
            ID NAME
    ---------- --------------------
             2 xyz
             1 abc
    
    Update tgt_Table tgt
       set Tgt.Name = 
          (select Src.Name
              from Src_Table Src
              where Src.id = Tgt.id
          );
    
    2 rows updated. --Notice that ID 1 is updated even though value did not change
    
    select * from Tgt_Table;
    
       ID NAME
    ----- --------------------
        2 def
        1 abc
    
    insert into tgt_Table
    select src.*
      from Src_Table src,
           tgt_Table tgt
      where src.id = tgt.id(+)
        and tgt.id is null;
    
    1 row created.
    
    SQL> select * from tgt_Table;
    
            ID NAME
    ---------- --------------------
             2 def
             1 abc
             3 ghi
    
    commit;
    

    There could be better ways to do this, but this seems simple and SQL-oriented. If the Data set is Large, then a PL/SQL solution won’t be as performant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.