Merge into Usage

Source: Internet
Author: User

1 rows have been created.  SQL> commit; ----Without a WHERE clause sql>  merge into merge1  2     using merge2 & Nbsp;3   ON (merge1.id = merge2.id)   4   When matched then  5     UPDATE&NBSP;&NBS P;6    set merge1.name = merge2.name; 3 line has been merged.  SQL> rollback;  fallback is complete.  ---with WHERE clause sql>   merge into Merge1 a  2    using merge2 b  3   on (a.id = b.id)   4   when matched then  5    update  6    set a.name = b.na Me  7   WHERE A.name <> b.name; 0 rows are merged.  ------If you want to update the B table, this will make an error sql>    merge into Merge1 a  2     using Merge2 b   3    on (a.id = b.id)   4    when matched then  5     UPDATE&NBSP;&NBSP;6     Set b.name = a.name;   Set b.name = a.name       * 6th error occurred: ORA-00904: "B". " NAME ': Invalid identifier----------------------------------------

; MERGE into loanee P
USING (SELECT * from @TApply as NC) C on P.applicationid=c.applicationid
when matched then UPD ATE set P.updatetime=getdate ()
When not matched by TARGET then INSERT
(
Loaneenumber,loaneename,loandate, Lockmatchratio,surplusmatchratio,
Matchratio,matchamount,lockamount,loaneeamount,expectedyield,
Loanperiod,creditrating,freestate,updatetime,addtime,
Deletestate,isfullstate,fulltime,loaneetype, ApplicationID,
Cashaccountno,contracttime,relaseratio,matchorder,ksshdate,
Lockstate,cashaccountno_name, Loaneesource,broker_cashaccount,broker_cashaccountname,approvaltime)
VALUES (
c.loaneenumber,c.[ loaneename],c.[loandate],0,1,
0,0,0,c.[loaneeamount],c.[expectedyield],
C.[loanperiod],c.[creditrating], 0,getdate (), GETDATE (),
0,0,null,0,c.[applicationid],
C.[cashaccountno],c.[contracttime],0,c.[matchorder] , [Ksshdate],
0,c.[cashaccountno_name],0,c.[broker_cashaccount],c.[broker_cashaccountname],c.approvaltime
);

The effect of the above example is that when inserting data into a table, it is determined whether it exists, does not exist, is inserted, and there is an update

Merge into Usage

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.