Oracle Batch update turn

Source: Internet
Author: User

Personally, I think it's a good writing.

http://blog.csdn.net/wanglilin/article/details/7200201

Demand:

Update the records in the T2 (T_STATBUF) table with the same ID as the T1 (T_MT) table into the T1 table.

1. The wrong wording:

1 update table_name T1 set (a,b,c)=( select a,b,c from Table_ name_2 T2 where t1.a=t2.a);

In this notation, all rows in the T1 table are updated: If t1.a=t2.a, the records detected in T2 are updated to T1, and if t1.a<>t2.a, the records in T1 are updated to empty (null).

The correct wording:

1 Update Set (A,B,C) = Select  from where t1.a=t2.a)2whereexists(select1  fromwhere t1.a=t2.a);  

Analytical:

The correct way to do this is to add a exists in the back (select 1 from table_name_2 T2 where t1.a=t2.a);

This sentence means: if there is t1.a=t2.a, update, otherwise, do not update, so will not cause all the records in the T1 table are updated.

Cases:

Update Table_name_1 Set (A, b) = (select from dual where 1=2);

This result will update all the records in the table_name_1 to null (NULL), since the 1=2 behind is not valid.

Summarize:

Update, to understand the qualification, to test!

My test statement:

1 Update Set = (Select   from 2 where t1. Discript=whereexists (select1from   3  where t1. Discript=T2. Discript);  

My business statement:

1 UpdateT_MT T1Set(Stat,ostat,rpttime)=(  2 SelectStat,stat,rpttime fromT_statbuf T2whereT1. MsgId=T2. MSGID)where exists(  3 Select 1  fromT_statbuf T2whereT1. MsgId=T2. MSGID);--if there are T1 and T2 equal, it is updated. Does not add where exists, whether the deposit does not exist, is updated, does not exist, the results will be updated to empty, but the record is still

Oracle Batch update turn

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.