oracle - 从另一个表更新一个表时改变触发器表
问题描述
运行此代码时表正在变异,请帮助我哪里出错了?谢谢
`CREATE OR REPLACE TRIGGER test_tri
after update of country ON test_1
for each row
when (new.country = 'SomeCountry')
begin
update test_2 set column_1 = 'Something'
where test_1.id = (Select id from test_1,test_2 where test_1.id=test_2.id) `
解决方案
试图澄清,而不是真正的答案;如果我理解你的需要,你的触发器过于复杂,你可能只需要:
CREATE OR REPLACE TRIGGER test_tri
AFTER UPDATE OF country
ON test_1
FOR EACH ROW
WHEN(new.country = 'SomeCountry')
BEGIN
UPDATE test_2
SET column_1 = 'Something'
WHERE test_2.id = :new.id;
END;
例如:
SQL> select *
2 from test_2;
ID COLUMN_1
---------- ----------------
1 xx
SQL> update test_1
2 set country = 'SomeCountry';
1 row updated.
SQL> select *
2 from test_2;
ID COLUMN_1
---------- ----------------
1 Something
这适用于这样的结构,没有触发器:
create table test_1 (id number, country varchar2(100));
create table test_2 (id number, column_1 varchar2(100));
如果您有不同的表、其他触发器等,请发布它们。
推荐阅读
- sql - 如何在查询结果中添加时间戳?
- r - 基于其他列分组的第三列中的值
- react-native - 反应图像名称控制台编号不是名称
- python - 是否可以保证这将是一个生成器?
- css - 如何修复:Sass/CSS 正在编译但未加载到浏览器元素中
- python - 将更改日期的电子邮件主题行添加到“接受的主题”列表中
- grails - 如何将数组值从 LInkedHashMap 转换为 List?
- android - 如何从 json 对象数组中通过 id 获取特定对象?
- sql-server - 在 SQL Server 中删除行只有一列为零
- c# - 是否有任何理由在 Task.Run 中运行异步代码?