Implementation of Multi-Table cascade update in Oracle

Source: Internet
Author: User

Implement Multi-Table cascade update. This method is safer:
-- First, set a cursor to store the required data in the cursor:
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 = 2008-2009 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:
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 _ = 2008-2009
And t. id _ = everyRow. id _;
End loop;
Commit;
End;

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.