Detailed description of Oracle multi-Table cascade update

Source: Internet
Author: User

Using a cursor, I think this method is absolutely safe.
-- First, set a cursor to store the required data in the cursor:
Copy codeThe Code is as follows:
Declare
CURSOR D_CURSOR_CUS_INFO IS
Select t3.id _ as id _,
T3.owe _ money _ as owe_money _,
A. heatingArea as heating_area _
From T_CUS_OWE_MONEY_2 t2
Left join T_CUS_OWE_MONEY_3 t3 on t2.id _ = t3.id _
Left join (select s. bh, sum (
Case
When s. stkbz = '0' then nvl (s. mj, 0)
When s. stkbz = '1' then 0-nvl (s. mj, 0)
End
) As heatingArea from sk s where s. nd = '2017-2008 'group by s. bh) a on t2.bh _ = a. bh
Where t3.owe _ money _-t2.owe _ money _ = a. heatingArea * 5 and t3.OWE _ MONEY _> 0;

-- Then the cyclic cursor updates the data:
Copy codeThe Code is as follows:
Begin
FOR everyRow IN D_CURSOR_CUS_INFO
Loop
Update T_CUS_YEAR_STATUS t
Set t. HEATING_AREA _ = everyRow. HEATING_AREA _,
T. OWE_MONEY _ = everyRow. owe_money _
Where t. YEAR _ = '2017-2008'
And t. id _ = everyRow. id _;
End loop;
Commit;
End;

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.