How to implement MySQL's two-table associated update operation in Oracle

Source: Internet
Author: User

When you look at the MySQL 5.1 reference manual, you find that MySQL provides a two-table associated update operation. The original text reads as follows:

UPDATE items,monthSET items.price=month.PriceWHERE items.id=month. ID;

Constructs a table in MySQL to verify a bit

Mysql> Select *  fromtest;+------+--------+|Id|Salary|+------+--------+|    1 |     - ||    2 |     $ ||    3 |     - |+------+--------+3Rowsinch Set(0.00sec) MySQL> Select *  fromtest1;+------+--------+|Id|Salary|+------+--------+|    1 |     - ||    2 |     - |+------+--------+2Rowsinch Set(0.00sec) MySQL> UpdateTest,test1SetTest.salary=Test1.salarywhereTest.id=test1.id; Query OK,2Rows Affected (0.00sec) Rows matched:2Changed:2Warnings:0MySQL> Select *  fromtest;+------+--------+|Id|Salary|+------+--------+|    1 |     - ||    2 |     - ||    3 |     - |+------+--------+3Rowsinch Set(0.00Sec

It is not difficult to see that the two tables associated with update only updated the row with ID 1 and ID 2 in test.

Think about it, Oracle does not seem to provide two tables associated with the update operation, also entered the above statement, Oracle error, error information as follows:

 sql>  update  test,test1 set  test.salary=  test1.salary where  test.id=  test1.id;  update  test,test1 set  Test.salary=  test1.salary =  Span style= "color: #000000;" >test1.id  *    1   line error: ORA  - 00971 : Missing set  keyword 

Later, check the official documents, this syntax is not supported, then how to achieve this effect in Oracle MySQL?

A bit of tinkering, though it came out, was somewhat complicated.

Sql> UpdateTestSetTest.salary=(SelectSalary fromTest1whereTest1.id=test.id)
where exists(Select 1 fromTest1whereTest1.id=test.id); 2 rows have been updated. SQL> Select * fromtest; ID SALARY---------- ---------- 1 - 2 - 3 -

How to implement MySQL's two-table associated update operation in Oracle

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.