Oracle uses a column in one table to update the column of the corresponding record in another table. When fields are accidentally updated, the column is empty.

Source: Internet
Author: User

At the beginning, I used the following method for searching online:

Update tbl1

Set (a. col1, a. col2) = (select B. col1, B. col2

From tbl2 B

Where a. key = B. key)

Then, after using it, I am miserable. After the operations I did directly on the server, I could not log on to the system. It was later found that the value of a field was empty because the statement was updated, and the view was used during login. This field is used when the view connects to the table. Many users failed to log on, which is really miserable!

Later, Baidu realized that this was the reason. If the tbl1.key value does not have this value in tbl2.key, the updated fields tbl1.col1 and tbl1.col2 will be updated to null ).

Speed draws on the writing of great gods:

Update tbl1

Set (a. col1, a. col2) = (select B. col1, B. col2

From tbl2 B

Where a. key = B. key)

Where a. key in (select key from tbl2) // This sentence is quite critical.

Special thanks to http://www.codesky.net/article/201004/167714.html!

Record this question for your reference and use.

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.