条件触发
create or replace trigger insert_test_id
before insert on test
where(test.name='Ash')
begin
insert into test(s_no) values('def');
end
我的桌子正在
测试 id 整数 名称 varchar2(200) s_no varchar2(250)
请告诉我此触发器中的错误是什么。我无法找出答案。
create or replace trigger insert_test_id
before insert on test
where(test.name='Ash')
begin
insert into test(s_no) values('def');
end
my table is
test
id integer
name varchar2(200)
s_no varchar2(250)
please tell me that what is the error in this trigger. I am not able to find out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
快速浏览一下在线文档已经告诉过您条件语法是 WHEN 而不是 WHERE。
您还应该使用 NEW 关键字而不是表名来引用该列。正如 Gary 正确指出的那样,我们只能对 ROW LEVEL 触发器应用条件子句:
条件也有效...
它甚至适用于多行...
那么问题是什么?这:
当然我在这里作弊,产生了错误。如果测试值和替换值都被硬编码,则可以避免该问题。但如果其中一个是查找,那么就存在递归的风险。
如果您实际想要做的是替换输入值而不是插入额外的行,您应该使用 简单的赋值语法由@Lukas发布。
A quick glance at the online documentation would have told you that the conditional syntax is WHEN not WHERE.
You should also reference the column using the NEW keyword rather than the table name. And as Gary rightly points out, we can only apply the conditional clause for ROW LEVEL triggers:
The condition works too...
It even works for multiple rows....
So what's the problem? This:
Of course I have cheated here, to generate the error. If both the test value and the substituted value are hard-coded the problem can be avoided. But if either is a lookup, then the risk of recursion is there.
If what you actually want to do is replace an input value rather insert an additional row you should use the simple assignment syntax posted by @Lukas.
然后试试这个:
“FOR EACH ROW”使其成为语句级触发器,针对受插入表影响的每一行执行。那应该摆脱 ora-04077
Try this one then:
The "FOR EACH ROW" makes it a statement level trigger, executed for each row affected by the insert into the table. That should get rid of the ora-04077
我认为您不能用这样的递归行为定义触发器。正确的方法是
但是,这只会插入一条记录,而不是两条记录,如果这是您的初衷的话。
I don't think you can define triggers with recursive behaviour like this. The correct way to do it is
However, this will only insert one record, not two, if that was your original intent.