Examples of usage in Oracle Merge into

Source: Internet
Author: User

Role: Merge into solution with B table and new a table data, if a table does not, then the B table data into a table;

Grammar:

MERGE into [Your table-name] [rename your table-here]

using ([Write your query here]) [rename your query-sql and using just like a table]

On ([conditional expression here] and [...] ... )

When mathed THEN [here you can execute some update SQL or something else]

When isn't mathed THEN [execute something else here!]

-------instance-------

Merge into a

Using (select Id,name from B) c

On (a.id=c.id)

When matched then update set A.name=c.name

When not matched then insert (a.id,a.name) values (c.id,c.name);

Role: Use table B with new Table A, if the condition is a.id=b.id, if data in table A does not have that condition inserted.

If you have a large amount of data, this SQL efficiency is very high.

Author: 51cto Blog Oracle Little Bastard

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

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.