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 ))