简体   繁体   English

在Oracle中的视图上触发

[英]Trigger on a view in oracle

I have a basic doubt..Can i use a trigger to insert changes on a view into a NEW table? 我有一个基本的疑问。我可以使用trigger insert视图中的更改insert到新表中吗?

example

create or replace trigger iam_insert
  instead of insert on test123
  FOR EACH ROW

BEGIN

  if inserting then

.
.
.
  end if;

end;

Regards 问候

Yes, that's the point of an INSTEAD OF trigger on a view. 是的,这就是视图上INSTEAD OF触发器的关键所在。 You can transform an INSERT against a complex view into any sort of DML operation on a base table (or on a table that the view doesn't even reference). 您可以将针对复杂视图的INSERT转换为基本表(或该视图甚至未引用的表)上的任何DML操作。

In general, though, it is pretty rare to encounter a situation where an INSTEAD OF trigger is really appropriate. 但是,总的来说,很少遇到真正适合INSTEAD OF触发器的情况。 They certainly exist, it's just rare. 它们确实存在,只是很少见。 If you are trying to allow inserts into the view to insert data into the base tables of the view, I would make absolutely certain that you can't ensure that the view itself is key-preserved which would allow you to do DML against the view without needing to define a trigger. 如果您试图允许在视图中插入数据以将数据插入到视图的基表中,那么我绝对可以确保不能确保视图本身是键保留的,这将允许您对视图进行DML无需定义触发器。

Yes, INSTEAD OF triggers are designed for this. 是的,为此设计了INSTEAD OF触发器。 Note that if you define an INSTEAD OF trigger on a view and then perform a data operation (such as an INSERT) on the view, your trigger will run in place of the operation. 请注意,如果在视图上定义INSTEAD OF触发器,然后在视图上执行数据操作(例如INSERT),则触发器将代替该操作运行。 Oracle will not automatically insert the data as it would without the trigger - that is now your responsibility. Oracle将不会像没有触发器那样自动插入数据-这是您的责任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM