假设有表 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的操作?
结构如下:
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的操作?
解决方案 »
- 关于like的复杂的问题
- 求教,如何提升数据插入的效率?
- 关于使用tera term工具访问Linux下的oracle数据库的问题!
- ORA-27101 Shared memory realm does not exist
- 很初级的一个问题 为什么我sqlplus dos 窗口下创建的表空间在 dbca里面看不到啊?
- 求一个存储过程
- 小弟用的是Oracle客户端。在SQL PLUS中输入的用户名称、主机字符串和口令都没问题,为什么一点“确定”就“未响应”啊?
- longraw 字段的问题!100分!
- 如何将 oracle 9i中的数据导入到oracle 8i中去???
- 我连到oracle sql*plus的时候报错,错误是。。。
- 存储过程游标插入数据避免重复数据问题
- 这样的触发器该如何写
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;
after insert on t1 t1是哪个表?是不是testtb呢?
create or replace trigger tr_test
befor update of col4 on testtbdeclare
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
)
又触发了触发器.这种情况有没有办法解决呢?
before insert of col4 on testtb 改成这个试试!对UPDATE不执行!如果确认要UPDATE 要执行,那换成在程序端判断!
以下可以参考一下:
create or replace trigger tr_test
befor update of col4 on testtb referencing old as old new as new
for each row
when 加入你的条件。