Two Oracle tables have the same structure. One is used as the source table, and the other is used as the supplementary table to synchronize the supplementary table data to the source table.

Source: Internet
Author: User
Table Structure
-- Create Table source table
Create Table input_fwmj
(
Jgbh char (5) not null,
Jgmc varchar2 (50) not null,
BmbH char (10) Not null,
BMMC varchar2 (50) not null,
Fwmj number (20, 2) not null,
Zlbz char (1) not null
)
-- Create/recreate primary, unique and foreign key constraints
Alter table input_fwmj
Add constraint organization no. And Department No. Primary Key (jgbh, BmbH)

-- Makeup table
-- Create Table
Create Table input_fwmj_change
(
Taskid number not null,
State varchar2 (100 ),
Jgbhsource char (5 ),
Bmbhsource char (10 ),
Jgbh char (5) not null,
Jgmc varchar2 (50) not null,
BmbH char (10) Not null,
BMMC varchar2 (50) not null,
Fwmj number (20, 2) not null,
Zlbz char (1) not null
)

-- Create/recreate primary, unique and foreign key constraints
Alter table input_fwmj_change
Add constraint pk_input_fwmj_change primary key (jgbh, BmbH, taskid)


-- Add
Insert
Into input_fwmj (jgbh, jgmc, BmbH, BMMC, fwmj, zlbz)
Select jgbh, jgmc, BmbH, BMMC, fwmj, zlbz
From input_fwmj_change
Where State = 'added'
-- Delete
Delete input_fwmj
Where jgbh | BmbH in
(Select jgbhsource | bmbhsource
From input_fwmj_change
Where input_fwmj_change.state = 'deleted ')
-- Modify
Update input_fwmj set
Input_fwmj.fwmj =
(Select input_fwmj_change.fwmj
From input_fwmj_change
Where input_fwmj_change.state = 'updated'
And input_fwmj_change.jgbhsource =
Input_fwmj.jgbh
And input_fwmj_change.bmbhsource =
Input_fwmj.bmbh ),
Input_fwmj.zlbz =
(Select input_fwmj_change.zlbz
From input_fwmj_change
Where input_fwmj_change.state = 'updated'
And input_fwmj_change.jgbhsource =
Input_fwmj.jgbh
And input_fwmj_change.bmbhsource =
Input_fwmj.bmbh)
Where exists (select 1
From input_fwmj_change
Where input_fwmj_change.state = 'updated'
And input_fwmj_change.jgbhsource =
Input_fwmj.jgbh
And input_fwmj_change.bmbhsource =
Input_fwmj.bmbh ))

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.