求一个触发器,急!

wangfengpp2004 2009-10-07 08:05:08
假设有表 testms ,testtb,testlist
结构如下:
testms: recno ,col1,col2,col3
testtb :recno,testmsrecno(和testms的recno关联),col4,col5
testlist:recno testtbrecno(和testtb的recno关联),col6,col7

现在我的需求如下:
当testtb的col4的字段的值变为Y时,触发触发器:
把testtb表中所有testmsrecno为:new.testmsrecno而且对应testlist的col6不为空的记录的col4的字段也变为Y
该怎么写触发器?
或者不用触发器,用其他办法来完成也好,但是在web页面中写的话感觉麻烦,
还有问下 当在testtb 表建立update trigger那么是不是不可在trigger中对此表进行select ,update delete的操作?

...全文
133 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zw393 2009-10-10
  • 打赏
  • 举报
回复
整的太复杂了
以下可以参考一下:
create or replace trigger tr_test
befor update of col4 on testtb

referencing old as old new as new
for each row
when 加入你的条件。
cosio 2009-10-09
  • 打赏
  • 举报
回复
commit;去掉,

create or replace trigger tr_test
before insert of col4 on testtb

改成这个试试!对UPDATE不执行!

如果确认要UPDATE 要执行,那换成在程序端判断!
wangfengpp2004 2009-10-08
  • 打赏
  • 举报
回复
我写update 触发器
create or replace trigger tr_test
befor update of col4 on testtb

declare
pragram autonomous_transaction;
begin
-- 执行代码
if :new.col4='Y' then
update testb b set col4='Y'
where b.recno in
(
select a.recno from testb a,testlist where a.recno=testtbrecno and testtbrecno=:new.testmsrecno and col6 is not null
)
end if;
commit;
end;
这样的话会报等待资源遇到一个死锁,因为 update testb b set col4='Y'
where b.recno in
(
select a.recno from testb a,testlist where a.recno=testtbrecno and testtbrecno=:new.testmsrecno and col6 is not null
)
又触发了触发器.

这种情况有没有办法解决呢?
cosio 2009-10-08
  • 打赏
  • 举报
回复
是testb上面写错了!
mowang45 2009-10-07
  • 打赏
  • 举报
回复
xuexiyixia
wangfengpp2004 2009-10-07
  • 打赏
  • 举报
回复
多谢了,明天上班试验一下
wangfengpp2004 2009-10-07
  • 打赏
  • 举报
回复
create or replace trigger tr_test
after insert on t1

t1是哪个表?是不是testtb呢?
wangfengpp2004 2009-10-07
  • 打赏
  • 举报
回复
t1是哪个表?是不是testtb呢?
cosio 2009-10-07
  • 打赏
  • 举报
回复
1.可以在程序中实现:


update testb b set col4='Y'
where b.recno in
(
select a.recno from testb a,testlist where a.recno=testtbrecno and col6 is not null
)

2.用自治事务
create or replace trigger tr_test
after insert on t1
for each row
declare
pragram autonomous_transaction;
begin
-- 执行代码
if :new.col4='Y' then
update testb b set col4='Y'
where b.recno in
(
select a.recno from testb a,testlist where a.recno=testtbrecno and testtbrecno=:new.testmsrecno and col6 is not null
)
end if;
commit;
end;

3,490

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧