Enhanced Merge in Oracle 10 GB

Source: Internet
Author: User

Create test table
Create table test1
SELECT *
FROM all_objects
WHERE 1 = 2;
MATCHED and not matched clauses are optional

① Both clauses appear.
Merge into test1
USING all_objects B
ON (a. object_id = B. object_id)
WHEN MATCHED THEN
Update set a. status = B. status
WHEN NOT MATCHED THEN
INSERT (object_id, status)
VALUES (B. object_id, B. status );
② ONLY insert operations, I .e. only the NOT MATCHED clause
Merge into test1
USING all_objects B
ON (a. object_id = B. object_id)
WHEN NOT MATCHED THEN
INSERT (object_id, status)
VALUES (B. object_id, B. status );
③ Only update operations, I .e. only MATCHED clauses
Merge into test1
USING all_objects B
ON (a. object_id = B. object_id)
WHEN MATCHED THEN
Update set a. status = B. status;

The source table can contain the WHERE clause.
① Updates and inserts contain the WHERE clause.
Merge into test1
USING all_objects B
ON (a. object_id = B. object_id)
WHEN MATCHED THEN
Update set a. status = B. status
WHERE B. status! = 'Valid'
WHEN NOT MATCHED THEN
INSERT (object_id, status)
VALUES (B. object_id, B. status)
WHERE B. status! = 'Valid ';
② Insert operations include the WHERE clause
Merge into test1
USING all_objects B
ON (a. object_id = B. object_id)
WHEN NOT MATCHED THEN
INSERT (object_id, status)
VALUES (B. object_id, B. status)
WHERE B. status! = 'Valid ';
③ Update operations include the WHERE clause
Merge into test1
USING all_objects B
ON (a. object_id = B. object_id)
WHEN MATCHED THEN
Update set a. status = B. status
WHERE B. status! = 'Valid ';
DELETE clause

You can use this clause to DELETE records that meet both the ON Clause conditions and the delete where clause conditions in the source table.
Merge into test1
USING all_objects B
ON (a. object_id = B. object_id)
WHEN MATCHED THEN
Update set a. status = B. status
WHERE B. status! = 'Valid'
Delete where (B. status = 'valid ');

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.