Oracle-update from explanation

Source: Internet
Author: User
Tags one table

In the update operation for a table, in many cases, you need to refer to data other than the table you want to update in an expression. Like SQL Server provides the FROM clause of the update, you can connect the table you want to update with its data source. Although only one table can be updated, it is possible to reference data other than the table to be updated in an update expression by connecting the table that will be updated with its data source.
For example:

UPDATE Table2 SET = + Table1.colb  from  INNERJOINon= Table1.cola);

The actual update is performed on the table to be updated, not on the new result set formed by the FROM clause.
Oracle does not have the update from syntax, and can be used in two ways to achieve the same functionality:

Subquery Update A SET a.name= (SELECT b.name from B WHERE b.id=a.id), this query is based on the specific situation to see if the work is as follows.

  

Single example: UPDATE A SET a.name= (select b.name from B where b.id=a.id) where a.id in (select ID from B)
Multiple example: UPDATE order_rollup SET (qty,price) = (SELECT sum (qty), SUM (price) from Order_lines where customer_id= ' KOHL ') where Cust _id= ' KOHL ' and order_period=to_date (' 01-oct-2000 ')

You can also use it in conjunction with a view.

  

There are three points to note:
1. For a given A.keyfield value, SELECT b.fieldsource from TableB b WHERE A.keyfield = B.keyfield value can only be a unique value and cannot be a multivalued value.
2. In most cases, the WHERE EXISTS clause in the final face is important, otherwise the result will be incorrect.
3. Limitations for View updates: If the view is based on connections from multiple tables, the ability to record the user update view is limited. The base table of the view cannot be updated unless update involves only one table and the View column contains the entire primary key of the table being updated.

Cut from: http://www.cnblogs.com/JasonLiao/archive/2009/12/23/1630895.html

Oracle-update from explanation

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.