---建立临时表
CREATE GLOBAL TEMPORARY TABLE ttt_Insprofworkty_insert
(
id NUMBER(10,0),
workid NUMBER(10,0),
worktypeid NUMBER(10,0),
projectid NUMBER(10,0),
ordervalue NUMBER(10,0)
);
CREATE GLOBAL TEMPORARY TABLE ttt_Delprofworktype_delete
(
id NUMBER(10,0),
workid NUMBER(10,0),
worktypeid NUMBER(10,0),
projectid NUMBER(10,0),
ordervalue NUMBER(10,0)
);
create or replace trigger profworktype_delete
before delete
on profworktype
FOR EACH ROW
-- 完成与删除的相同workid且大于当前删除ordervalue的操作
DECLARE
begin
insert into ttt_Delprofworktype_delete values (:old.id,:old.workid,:old.worktypeid,:old.projectid,:old.ordervalue);
end;
------------------------------------
create or replace trigger profworktype_insert
before insert
on profworktype
FOR EACH ROW
DECLARE
BEGIN
select S_profworktype.NEXTVAL INTO :new.id from dual;
insert into ttt_insprofworkty_insert values(:new.id,:new.workid,:new.worktypeid,:new.projectid,:new.ordervalue);
END;
---------------------------------
语句触发器完成业务
create or replace trigger profworktype_statement
after delete or insert
on profworktype
-- 完成与删除的相同workid且大于当前删除ordervalue的操作
DECLARE
v_count NUMBER(10,0);
cursor cur_del is select * from ttt_Delprofworktype_delete deleted;
cursor cur_ins is select * from ttt_Insprofworkty_insert inserted;
begin
if deleting then
begin
for i in cur_del loop
begin
-- dbms_output.put_line('-------'||i.ordervalue);
update profworktype set ordervalue = ordervalue -1 where workid = i.workid and ordervalue > i.ordervalue ;
end ;
end loop;
delete from Ttt_Delprofworktype_Delete;
end ;
end if;
-----
if inserting then
begin
for i in cur_ins loop
begin
v_count := 0;
select count(*) INTO v_count from profworktype where ordervalue is not null and workid = i.workid;
update profworktype set ordervalue = v_count+1 where id =i.id;
end ;
end loop;
delete from ttt_Insprofworkty_insert;
end ;
end if;
end;