update rs_rzqk set
zgbh='500067',zw='1220A',rmzbz='1',pzwh='pzwh01',rzsj=to_date('2009-11-20','YYYY-MM-DD'),zwbdfs='1',
bz='备注',ssbm='人事处',zwjb='9',rzjzsj=to_date('2009-7-1','YYYY-MM-DD'),szks='人才引进办公室',
xzw='1220A',yssbm='人事处',yszks='人才引进办公室',yzwjb='9',shzt='4',
shsj=to_date('2009-11-20','YYYY-MM-DD'),
rtjsj=to_date('2009-11-20','YYYY-MM-DD'),
yssdw='网络工程',xssdw='计算机科学与技术'
where id='168134';create or replace trigger TRIG_RS_RZQK_NEW
after insert or update of rzsj on rs_rzqk
for each row
when (new.shzt='4')
declare
-- local variables here
xssdwdm varchar2(32);
xssdwmc varchar2(64);
date_temp date;
begin
dbms_output.put_line('修改');
--选取时间最大的一条记录
select max(rzsj) into date_temp from rs_rzqk t where t.zgbh=:new.zgbh; ---------这一句出错,高手看看是怎么回事
end TRIG_RS_RZQK_NEW;
不知怎么查看触发器里参数变量的值,
zgbh='500067',zw='1220A',rmzbz='1',pzwh='pzwh01',rzsj=to_date('2009-11-20','YYYY-MM-DD'),zwbdfs='1',
bz='备注',ssbm='人事处',zwjb='9',rzjzsj=to_date('2009-7-1','YYYY-MM-DD'),szks='人才引进办公室',
xzw='1220A',yssbm='人事处',yszks='人才引进办公室',yzwjb='9',shzt='4',
shsj=to_date('2009-11-20','YYYY-MM-DD'),
rtjsj=to_date('2009-11-20','YYYY-MM-DD'),
yssdw='网络工程',xssdw='计算机科学与技术'
where id='168134';create or replace trigger TRIG_RS_RZQK_NEW
after insert or update of rzsj on rs_rzqk
for each row
when (new.shzt='4')
declare
-- local variables here
xssdwdm varchar2(32);
xssdwmc varchar2(64);
date_temp date;
begin
dbms_output.put_line('修改');
--选取时间最大的一条记录
select max(rzsj) into date_temp from rs_rzqk t where t.zgbh=:new.zgbh; ---------这一句出错,高手看看是怎么回事
end TRIG_RS_RZQK_NEW;
不知怎么查看触发器里参数变量的值,
select max(rzsj) into date_temp from ...要实现的是什么需求?
我的需求是:
在这个表中,一个职工可能会有N条记录,在更新一个职工的某条记录时,我要得到这个职工最新的一条记录的rzsj(任职时间).如他有三条记录时间为(2009-2-1,2009-3-1,2009-10-1) ,我本来是通过这条语句来
select max(rzsj) into date_temp from rs_rzqk t where t.zgbh=:new.zgbh;将他的最新的一条记录的时间(2009-10-1)附值给我在触发器中定义的一个变量date_temp.
但是我在测试时,运行到这句select max(rzsj) into date_temp from rs_rzqk t where t.zgbh=:new.zgbh;就出错,刚学这个不知是什么原因????? ---高手解答下,谢谢了!
因此会报变异表错误。
可以通过别的方法来解决
不知道在此触发器中date_temp这个变量有什么作用
before insert or update of rzsj on rs_rzqk
for each row
when (new.shzt='4')
declare
-- local variables here
xssdwdm varchar2(32);
xssdwmc varchar2(64);
date_temp date ;
begin
--选取时间最大的一条记录
select max(rzsj) into date_temp from rs_rzqk t where t.zgbh=:new.zgbh;
--查询填写的单位是否在dept表中
select d.id,d.dept_name into xssdwdm,xssdwmc from dept d where :new.xssdw=d.dept_name
and rownum=1;
--如果所填的单位存在并且这是最新的任(免)职记录,刚进行更新
if xssdwdm is not null and :new.rzsj=date_temp then
update rs_zgjbxx r set r.dept = xssdwdm where :new.zgbh = r.zgbh;
update sys_yh s set s.v_ssdw = xssdwdm where :new.zgbh = s.c_bh;
end if;
end TRIG_RS_RZQK_NEW;
select max(rzsj) into date_temp from rs_rzqk t where t.zgbh=:new.zgbh;
出错!!!!
郁闷,不知道有什么办法解决!!!
--加个自治事务
create or replace trigger TRIG_RS_RZQK_NEW
after insert or update of rzsj on rs_rzqk
for each row
when (new.shzt='4')
declare
--自治事务开始
pragma autonomous_transaction; xssdwdm varchar2(32);
xssdwmc varchar2(64);
date_temp date;
begin
dbms_output.put_line('修改');
select max(rzsj) into date_temp from rs_rzqk t where t.zgbh=:new.zgbh;
--自治事务结束
commit;
end TRIG_RS_RZQK_NEW;
补充一点:我疑惑楼主用这个触发器干嘛使?只有select没有任何操作,如果仅仅是为了举个例子那就罢了。
还有,自治事务只能解决这种select本表 或者 类似触发器是update触发器而你要在触发器中insert的情况,不能处理如update触发器中还有update语句的。 我说的全是指操作本表。
自治事务中无法读到刚更新或插入的,尚未commit的数据
有点棘手
不知道为什么会有这个需求