1Z0-052 · Question #80
The TRANS_SUMMARY table contains product-wise transaction details that get updated with every transaction in the system. Each row has cumulative transaction details of a single product and every…
The correct answer is A. Using the MERGE command. The MERGE statement is best for this scenario because it handles both updating existing product rows and inserting new product rows in a single atomic operation.
Question
The TRANS_SUMMARY table contains product-wise transaction details that get updated with every transaction in the system. Each row has cumulative transaction details of a single product and every product is identified by a product code, which is the primary key. As part of the archival process, the company wants to transfer the rows in the TRANS_SUMMARY table to the TRANS_SUMMARY_DUP table at the end of every quarter of the year. Along with existing products, the company deals with many new products during every quarter. Which method is best suited for this quarterly data transfer?
Options
- AUsing the MERGE command
- BUsing the SQL*Loader utility
- CUsing the correlated UPDATE command
- DUsing the INSERT command to perform bulk operation
How the community answered
(48 responses)- A71% (34)
- B8% (4)
- C17% (8)
- D4% (2)
Why each option
The MERGE statement is best for this scenario because it handles both updating existing product rows and inserting new product rows in a single atomic operation.
MERGE (also called UPSERT) evaluates each source row against the target table - when a matching product code exists it performs an UPDATE, and when no match is found it performs an INSERT. This exactly satisfies the requirement that existing products are updated and new products are added each quarter. Using MERGE also avoids primary key constraint violations that a plain INSERT would cause for already-existing rows.
SQL*Loader is designed to load data from external flat files into Oracle tables, not to transfer data between two tables that already exist within the same database.
A correlated UPDATE can only modify existing rows in the target table; it cannot insert rows for new products that do not yet exist in TRANS_SUMMARY_DUP.
A plain INSERT would attempt to insert all rows including those with product codes already present in TRANS_SUMMARY_DUP, causing primary key constraint violations for existing products.
Concept tested: Oracle MERGE statement for conditional insert and update
Source: https://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_9016.htm
Topics
Community Discussion
No community discussion yet for this question.