Oracle 10g update syntax is more named Oracle update statement Optimization Research

Source: Internet
Author: User

 

I. syntax and Principles of the update Statement 1. Syntax single table: Update table name set column name = new value where column name = A value such as: Update t_join_situationset
Join_state = '1' whereyear = '000000' the join_state field of the Data updated for the Year "2011" is "1 ". If the updated field is indexed, the index will be re-created during the update, and the update efficiency will be slow. Associate multiple tables and update the field values of one table to the fields in another table: Update table a set. field 1 = (select B. field 1 from Table B where. field 2 = B. field 2) where exists (select 1 from Table B where. field 2 = B. field 2) the Oracle update statement is not as easy to write as MSSQL. Even if it is written, it may be reported during execution because multiple rows of data are found in the sub-query of set, oracle requires one-to-one data update, so an error is prompted. To solve this problem, we must ensure that the retrieved values correspond one to one. 2. principle the principle of the update statement is to first find the data based on the where condition. If a subquery exists in the Set, execute the subquery to find the value and assign it to the updated field for update. For example, update table a set a. Field 1 = (select B. Field 1 from Table B where a. Field 2 = B. Field 2)
Where exists (select 1 from Table B where a. Field 2 = B. Field 2 ). Query all the data in Table A and recyclically check whether the data conforms to exists (select 1 from Table B where. field 2 = B. field 2) condition. If yes, execute (select B. field 1 from Table B where. field 2 = B. field 2) query, find the corresponding value update. field 1. When updating the joined table, you must have exists (select 1 from Table B where. field 2 = B. field 2). Otherwise, Field 1 of other data in Table A is updated to null. Reference http://chenxy.blog.51cto.com/729966/811672

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.