TRIGGERS_监测系统_多表视图触发器—向原始数据报表中插入数据
Create Or Replace Trigger trg_view_report
Instead Of Insert or update or delete on view_for_report
for each row
Declare
begin
If Inserting Then
if :new.temperature1 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
1,
'传感器一',
:new.year,
:new.month,
:new.day,
:new.temperature1,
:new.humidity1);
end if;
if :new.temperature2 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
2,
'传感器二',
:new.year,
:new.month,
:new.day,
:new.temperature2,
:new.humidity2);
end if;
if :new.temperature3 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
3,
'传感器三',
:new.year,
:new.month,
:new.day,
:new.temperature3,
:new.humidity3);
end if;
if :new.temperature4 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
4,
'传感器四',
:new.year,
:new.month,
:new.day,
:new.temperature4,
:new.humidity4);
end if;
if :new.temperature5 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
5,
'传感器五',
:new.year,
:new.month,
:new.day,
:new.temperature5,
:new.humidity5);
end if;
if :new.temperature6 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
6,
'传感器六',
:new.year,
:new.month,
:new.day,
:new.temperature6,
:new.humidity6);
end if;
if :new.temperature7 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
7,
'传感器七',
:new.year,
:new.month,
:new.day,
:new.temperature7,
:new.humidity7);
end if;
if :new.temperature8 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
8,
'传感器八',
:new.year,
:new.month,
:new.day,
:new.temperature8,
:new.humidity8);
end if;
if :new.temperature9 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
9,
'传感器九',
:new.year,
:new.month,
:new.day,
:new.temperature9,
:new.humidity9);
end if;
if :new.temperature10 <= 250 then
insert into originaldata_report
(id,
wid,
wname,
jurisdiction,
jurisdiction_name,
year,
month,
day,
temperature,
humidity)
values
(originaldata_report_id.nextval,
:new.wid,
:new.wname,
10,
'传感器十',
:new.year,
:new.month,
:new.day,
:new.temperature10,
:new.humidity10);
end if;
elsif Deleting then
Delete from originaldata_report t where t.wid = :Old.wid;
End if;
end ;