Oracle has no solution for update from ____oracle

Source: Internet
Author: User
Tags one table

Oracle does not have the update from syntax, which enables the same functionality in two ways:
1: Subquery update A SET a.name= (SELECT b.name from B WHERE b.id=a.id), this query will be based on the specific situation to see if the following are flexible
(1) Single column
UPDATE A

SET a.name= (SELECT b.name from B WHERE b.id=a.id)

WHERE a.id in (SELECT ID from B);

(2) Multiple columns
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 ')


2: Use a view to do
UPDATE (SELECT a.name aname,b . NAME bname from A,b WHERE a.id=b.id)
SET aname=bname;

Example:

UPDATE TableA a
SET a.fieldforupdate = (SELECT b.fieldsource from TableB b WHERE A.keyfield = B.keyfi ELD)
where EXISTS (SELECT b.fieldsource from TableB b WHERE a.keyfield = B.keyfield)

has 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, not multi-valued.
2. In most cases, the last side of the WHERE EXISTS clause is important, otherwise you will get the wrong result. Because if you do not add this sentence, all records that do not match the primary table will be updated to NULL.
3. Restrictions on view updates:
If the view is based on a connection of multiple tables, the ability to record the user update view is limited. The base table of the view cannot be updated unless the update involves only one table and the View column contains the entire primary key of the table being updated.

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.