Oracle update multi-Table Association

Source: Internet
Author: User

Update A. A3 = A. A3 + B. B3

Table A structure: A1, A2, A3
Table B structure: B1, B2, B3
A1 and B1 are PK, and A1 = B1 can be used if the cut value is the same.

How can I implement the following functions using SQL statements or procedures ???

Update A3 of Table A with the sum of A. A3 and B. B3.

3> Update
Set a3 = (select a. A3 + B. B3 from B where a. A1 = B. B1 );

7> Update (select A1, A3, B1, B3 from a, B where a1 = b1) set a3 = A3 + B3

Opening an execution plan and talking about efficiency is meaningless ..

The writing on the third floor is different from the writing on the seventh floor.

The Writing Method on the third floor updates all records, while the Writing Method on the seventh floor only modifies the information related to the intersection of the two.

The statement on the 7th floor can easily control the execution plan of the update statement, but table B must have a primary key index on the corresponding field :), if table B has a primary key index on the corresponding field, we recommend that you write the index on the 7th floor.

Refer to this post ^_^.

Http://www.cnoug.org/viewthread.php? Tid = 44070 (the test was not successful... I don't know how to do it) refer to the following: I admire it very much. With a learning attitude, I have rewritten the third floor. If there is no primary key, please advise:
Update
Set a3 = (select A3 + B3 from B where a1 = b1)
Where a1 = (select B1 from B where a1 = b1): Update con_eme_on20050309 a set. con_price = (select. con_price + (B. annuity-a.annuity) +. nojob-a.nojob) +. medicare-a.medicare) +. birthfee-a.birthfee) +. bruisefee-a.bruisefee) from con_eme_on200404 B where. emp_cod = B. emp_cod and. if_act = '1' and. emp_base! = B. emp_base), A. emp_base = (select B. emp_base from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. annuity = (select B. annuity from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. nojob = (select B. nojob from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. Medicare = (select B. Medicare from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. birth1_= (select B. birth1_from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. bruisefee = (select B. bruisefee from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. nojobbase = (select B. nojobbase from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. mediabase = (select B. mediabase from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. birthbase = (select B. birthbase from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. bruisebase = (select B. bruisebase from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base)
Where a. emp_cod in (select B. emp_cod from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base) Provident Fund: Update con_eme_on20050309 a set. con_price = (select. con_price + (B. accumulation-a.accumulation) from con_eme_on200404 B where. emp_cod = B. emp_cod and. if_act = '1' and. emp_base! = B. emp_base), A. Accumulation = (select B. accumulation from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. accumulationbase = (select B. accumulationbase from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base), A. accumulationbase1 = (select B. accumulationbase1 from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base)
Where a. emp_cod in (select B. emp_cod from con_eme_on200404 B where a. emp_cod = B. emp_cod and A. if_act = '1' and A. emp_base! = B. emp_base)

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.