Oracle database, overwriting insert data----Merge into

Source: Internet
Author: User

In the development we often encounter such a scene, column, such as user modification simple personal basic information, this time need to determine whether the user's basic information exists, if the first entry does not exist in the table insert a message, if there is the Update table information.
To achieve this kind of scenario is very simple, our most commonly used is to query the user's basic information, execute the Select method, if the data exists on the implementation of the Update method, if it does not exist, execute the Insert method. This is a solution to the idea.
When it is simply a condition to judge, we also have another kind of database-level solution is merge into, many databases have this statement, because I use Oracle, here to record the use of Oracle, from version 9 to support the syntax.

MERGEINTO table_name t1USING (Select A, b b,c C from dual) T2On (t1. A = t2.a)when matched then UPDATE T1 SET b= B, c= C is not matched then   INSERT t1  
                      
                       values (a,b,c); 
                               

Oracle database, overwriting insert data----Merge into

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.