JDBC uses the merge into function in Oracle

Source: Internet
Author: User
Tags auth one table

Merge into enables the merging of existing data in an Oracle data table. Update if it is available


The following example is a test pass after the JDBC data source is connected


1. Single Data

Long Companyauthid = Seqkeyutil.getseqkey (vids, "company_auth_id"); Companyauth comtmp = companylist.get (0); String sql = "Merge into Company_auth AUTH using (select? MOBILE from dual) TMP on (auth.mobile=tmp.mobile) "+" while matched then "+" UPDATE SET auth.reserve=? " + "When not matched then" + "INSERT (id,mobile) VALUES (?,?)"; Vids.update (SQL, New Object[]{comtmp.getmobile (), Comtmp.getreserve (), companyauthid+ "", Comtmp.getmobile ()});

2. Multiple data (batch processing)

Long Companyauthid = Seqkeyutil.getseqkey (vids, "company_auth_id"),//SEQS table primary key using list<object[]> batch = new   Arraylist<object[]> (); for (Companyauth company:companylist) {object[] values = new object[] {company.getmobile (), Company.getreserve (), Compan Yauthid+ "", Company.getmobile ()};  Batch.add (values); }string sql = "Merge into Company_auth AUTH using (select? MOBILE from dual) TMP on (auth.mobile=tmp.mobile) "+" while matched then "+" UPDATE SET auth.reserve=? " + "When not matched then" + "INSERT (id,mobile) VALUES (?,?)"; Vids.batchupdate (SQL, batch);

If more than one table is present, you only need to target the using (select? MOBILE from dual) TMP on modify




JDBC uses the merge into function in 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.