The saveOrUapdate and mergesaveoruapdate in merge into Oracle

Source: Internet
Author: User

The saveOrUapdate and mergesaveoruapdate in merge into Oracle

1. Initial data:

SQL> select * from a; ID                     NAME---------------------- ----------------------1                      12                      13                      14                      15                      1SQL> select * from b; ID                     NAME---------------------- ----------------------1                      22                      211                     11

2. Objective: 1) update. name to B. name prevails; 2) if the id in Table B is not in Table a, copy the record in Table B and insert it to Table.

3. function implementation:

Merge into A a using B B on (. id = B. id) -- on is the matching condition when matched then -- Update. nameupdate set. name = B. name where 1 = 1 -- here we can add the where condition when not matched then -- copy and insert binsert values (B. id, B. name) where 1 = 1

  

 


Oracle problems? What about merge into in oracle?

Compare the two tables. You can compare the insert, update, and delete tables.
 
ORACLE usage of merge

After when matched then and when not matched then, only insert () values or update set ....,...., conditions cannot be attached, and other statements following then cannot be used. In addition, it is noted that the B domain is only useful for queries in using. If you want to use it, you must use M in Using () m.

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.