create or replace trigger trigger_task_work
after update on yp_work_task
for each row
-- local variables here
--- add by lanwei 2012-05-28
--- 游标获取任务的参与人数
declare cursor
mytask(taskid NUMBER) is
select t_ruser
from YP_WORK_TASKFEEDUSER
where t_code = taskid;
li_count NUMBER;
ls_tjyd NVARCHAR2(6); -- 统计月度
userid NVARCHAR2(10); -- 用户ID
li_tasking_count NUMBER; --正在处理的任务数
ls_username NVARCHAR2(40);
li_departid int;
ls_departname NVARCHAR2(40);
begin
ls_username :='';
li_departid :=0;
ls_departname :='' ;
li_tasking_count :=0;
-----修改
if updating then
if :old.t_state <> :new.t_state then
if :new.t_state=2 or :new.t_state=3 then
open mytask(:new.t_id);
fetch mytask into userid;
while mytask%found
loop
select count(*) into li_tasking_count
from YP_WORK_TASKFEEDUSER a
where a.t_ruser=userid and a.t_taskstate=2;
select count(*) into li_count from YP_TASK_M_REPORT b where b.tjyd=to_char(sysdate,'yyyymm') and b.userid=userid;
if li_count>0 then
update YP_TASK_M_REPORT c set c.taskingcounts=li_tasking_count
where c.tjyd=to_char(sysdate,'yyyymm') and c.userid=userid;
else
select trim( a.name) , a.departid, trim(b.name)
into ls_username , li_departid , ls_departname
from YP_ACCOUNT_USER a , yp_info_department b
where a.departid =b.departid and a.userid =userid;
insert into YP_TASK_M_REPORT( TJYD , USERID ,USERNAME ,DEPARTID ,DEPARTNAME ,
NEWTASKCOUNTS , TASKINGCOUNTS , TASKENDCOUNTS , TASKMARKCOUNTS , EXCELLENTCOUNTS ,
GOODCOUNTS , GENERALCOUNTS ,MARKCOUNTS , SCORE , CREATEDATE , MODIFYDATE )
values(ls_tjyd,userid,ls_username,li_departid,ls_departname,0,li_tasking_count,0,0,0,0,0,0,100,sysdate,sysdate);
end if;
fetch mytask into userid;
end loop;
close mytask; --4.关闭游标
end if;
end if;
end if;
end trigger_task_work;
after update on yp_work_task
for each row
-- local variables here
--- add by lanwei 2012-05-28
--- 游标获取任务的参与人数
declare cursor
mytask(taskid NUMBER) is
select t_ruser
from YP_WORK_TASKFEEDUSER
where t_code = taskid;
li_count NUMBER;
ls_tjyd NVARCHAR2(6); -- 统计月度
userid NVARCHAR2(10); -- 用户ID
li_tasking_count NUMBER; --正在处理的任务数
ls_username NVARCHAR2(40);
li_departid int;
ls_departname NVARCHAR2(40);
begin
ls_username :='';
li_departid :=0;
ls_departname :='' ;
li_tasking_count :=0;
-----修改
if updating then
if :old.t_state <> :new.t_state then
if :new.t_state=2 or :new.t_state=3 then
open mytask(:new.t_id);
fetch mytask into userid;
while mytask%found
loop
select count(*) into li_tasking_count
from YP_WORK_TASKFEEDUSER a
where a.t_ruser=userid and a.t_taskstate=2;
select count(*) into li_count from YP_TASK_M_REPORT b where b.tjyd=to_char(sysdate,'yyyymm') and b.userid=userid;
if li_count>0 then
update YP_TASK_M_REPORT c set c.taskingcounts=li_tasking_count
where c.tjyd=to_char(sysdate,'yyyymm') and c.userid=userid;
else
select trim( a.name) , a.departid, trim(b.name)
into ls_username , li_departid , ls_departname
from YP_ACCOUNT_USER a , yp_info_department b
where a.departid =b.departid and a.userid =userid;
insert into YP_TASK_M_REPORT( TJYD , USERID ,USERNAME ,DEPARTID ,DEPARTNAME ,
NEWTASKCOUNTS , TASKINGCOUNTS , TASKENDCOUNTS , TASKMARKCOUNTS , EXCELLENTCOUNTS ,
GOODCOUNTS , GENERALCOUNTS ,MARKCOUNTS , SCORE , CREATEDATE , MODIFYDATE )
values(ls_tjyd,userid,ls_username,li_departid,ls_departname,0,li_tasking_count,0,0,0,0,0,0,100,sysdate,sysdate);
end if;
fetch mytask into userid;
end loop;
close mytask; --4.关闭游标
end if;
end if;
end if;
end trigger_task_work;
本文介绍了一个Oracle PL/SQL触发器的实现细节,该触发器在任务状态更改时更新任务月报,涉及游标使用、条件判断及数据更新等关键步骤。
1072

被折叠的 条评论
为什么被折叠?



