Oracle batch modify multi-column multi-row data to http://5icto.blog.51cto.com/3431949/714387

Source: Internet
Author: User

How to update different data before two tables? There must be different data conditions for multiple fields in multiple data entries. The following is an example:

1. Create a table

    1. Create TableTb1
    2. (ID varchar2 (10 ),
    3. XM varchar2 (10 ),
    4. XB varchar2 (10 ));
    5.  
    6. Create TableTb2
    7. (ID varchar2 (10 ),
    8. XM varchar2 (10 ),
    9. XB varchar2 (10 ));

2. Insert Test Data

  1. Insert IntoTb1Values('1','Xx','Xx');
  2. Insert IntoTb1Values('2','Yy','Yy');
  3. Insert IntoTb1Values('3','Zz','Zz');
  4. Insert IntoTb1Values('5','Mm','Mm');
  5.  
  6. Insert IntoTb2Values('1','1','1');
  7. Insert IntoTb2Values('2','2','2');
  8. Insert IntoTb2Values('3','3','3');
  9. Insert IntoTb2Values('4','4','4');

3. The following two methods are provided to execute the following SQL statement and view the result:

 

  1. Update Tb2 Set XM = ( Select XM From Tb1 Where Tb1.id = tb2.id), XB = ( Select XB From Tb1 Where Tb1.id = tb2.id)   WhereIDIn(SelectIDFromTb1 );
  2.  
  3. Update tb2 set (XM, XB) = ( select XM, XB from tb1 where tb1.id = tb2.id) where id in ( select id from tb1);

4. Pay attention to the aboveRedAfter removing the labeled SQL statement, perform the test. What is the difference.

5. After the test, delete the table. Develop good habits.

      1. Drop TableTb1;
      2. Drop TableTb2;
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.