oracle 更新后触发器(after update)
2011-04-09 15:37
169 查看
oracle 触发器,我不太喜欢,因为以前的一个项目用的太多了,几乎每一个业务表都有触发器,后来维护这个项目时很费劲。
提醒一下:oracle 触发器更新表之后,这张表,就不能在你的触发器中随意使用,比如查询之类。
--创建包 ,封装所需数据
create or replace package pkg_mail_param
as
type attendancenotcardinfo is record
(
attendance_fid t_hr_attendancemanager.fid%type,
leavebillentry_ftypeid t_hr_leavebillentry.ftypeid%type,
timeattendance_unittype t_hr_timeattendance.funittype%type
);
type cur_attendancenotcard is ref cursor return attendancenotcardinfo;
end pkg_mail_param;
/
create or replace trigger tri_after_update_leavebill
after update of fstate
on t_hr_leavebill
for each row
declare
cur_notcardinfo pkg_mail_param.cur_attendancenotcard;
v_attmanager_rowtype cur_notcardinfo%rowtype;
v_billid varchar2(50);
begin
v_billid := :new.fid;
if :new.fstate = 3 and :new.fisnotcard = 1 then
-- 查找出与考勤表有关联的记录
open cur_notcardinfo for
select
attendance.fid,
info.ftypeid,
info.funittype
from t_hr_attendancemanager attendance
inner join
(select
billentry.fpersonid,
billentry.fbegintime,
billentry.fendtime,
billentry.ftypeid,
timeattendance.funittype
from t_hr_leavebillentry billentry
left join t_hr_timeattendance timeattendance on timeattendance.fid = billentry.ftypeid
where billentry.fbillid = '' || v_billid || '') info
on attendance.fpersonid = info.fpersonid and attendance.fstartdate = info.fbegintime and attendance.fenddate = info.fendtime;
loop
fetch cur_notcardinfo into v_attmanager_rowtype;
exit when cur_notcardinfo%notfound;
update
t_hr_attendancemanager tabAM
set
tabAM.Ftotalvalue = 1,
tabAM.Fattendanceid = v_attmanager_rowtype.leavebillentry_ftypeid
where tabAM.Fid = v_attmanager_rowtype.attendance_fid;
end loop;
close cur_notcardinfo;
end if;
exception
when others then
DBMS_OUTPUT.put_line(DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line(DBMS_UTILITY.format_call_stack);
end tri_after_update_leavebill;
提醒一下:oracle 触发器更新表之后,这张表,就不能在你的触发器中随意使用,比如查询之类。
--创建包 ,封装所需数据
create or replace package pkg_mail_param
as
type attendancenotcardinfo is record
(
attendance_fid t_hr_attendancemanager.fid%type,
leavebillentry_ftypeid t_hr_leavebillentry.ftypeid%type,
timeattendance_unittype t_hr_timeattendance.funittype%type
);
type cur_attendancenotcard is ref cursor return attendancenotcardinfo;
end pkg_mail_param;
/
create or replace trigger tri_after_update_leavebill
after update of fstate
on t_hr_leavebill
for each row
declare
cur_notcardinfo pkg_mail_param.cur_attendancenotcard;
v_attmanager_rowtype cur_notcardinfo%rowtype;
v_billid varchar2(50);
begin
v_billid := :new.fid;
if :new.fstate = 3 and :new.fisnotcard = 1 then
-- 查找出与考勤表有关联的记录
open cur_notcardinfo for
select
attendance.fid,
info.ftypeid,
info.funittype
from t_hr_attendancemanager attendance
inner join
(select
billentry.fpersonid,
billentry.fbegintime,
billentry.fendtime,
billentry.ftypeid,
timeattendance.funittype
from t_hr_leavebillentry billentry
left join t_hr_timeattendance timeattendance on timeattendance.fid = billentry.ftypeid
where billentry.fbillid = '' || v_billid || '') info
on attendance.fpersonid = info.fpersonid and attendance.fstartdate = info.fbegintime and attendance.fenddate = info.fendtime;
loop
fetch cur_notcardinfo into v_attmanager_rowtype;
exit when cur_notcardinfo%notfound;
update
t_hr_attendancemanager tabAM
set
tabAM.Ftotalvalue = 1,
tabAM.Fattendanceid = v_attmanager_rowtype.leavebillentry_ftypeid
where tabAM.Fid = v_attmanager_rowtype.attendance_fid;
end loop;
close cur_notcardinfo;
end if;
exception
when others then
DBMS_OUTPUT.put_line(DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line(DBMS_UTILITY.format_call_stack);
end tri_after_update_leavebill;
相关文章推荐
- oracle 触发器更新基表不同记录所产生的问题
- oracle 使用触发器更新插入列的id
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入|更新|删除,两表同步
- Oracle前置更新触发器
- Oracle 触发器更新本表数据
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 多表视图更新(待看完触发器后再来看)
- oracle 如何用触发器实现更新刚插入的数据
- aa75 Oracle 触发器 插入,更新,删除,数据同步,两表同步
- 用触发器干扰更新值(Oracle)
- oracle视图更新,替代触发器(转)
- oracle 如何用触发器实现更新刚插入的数据集合
- oracle视图更新,替代触发器
- ORACLE使用触发器更新数据
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- 项目经验:oracle中一个用户赋予另外一个用户对表增删改查的权限以及同步更新触发器的创建
- 【Oracle】触发器更新栏位后自动更新某栏位
- Oracle 触发器 插入,更新,删除,数据同步,两表同步