摆脱插入触发器
尝试探索使用插入触发器的替代解决方案。比如基于 API 的方法以及不同方法的优缺点。
Trying to explore solutions alternative to using insert triggers. Like API based ones and pros and cons with different approaches.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 API 方法中,您将创建一个过程来执行这两种操作 - 类似于:
然后,您通过授予应用程序对 api 包的 EXECUTE 访问权限,但不授予其 INSERT/UPDATE/DELETE 访问权限来强制应用程序使用 API。桌子。
In an API approach you would create a procedure to perform both operations - something like:
Then you force applications to use the API by giving them EXECUTE access to the api package but no INSERT/UPDATE/DELETE access to the tables.
如果您想保证在向 tableA 插入数据时会将记录插入到 tableB 中,则保留触发器。您可以禁用批量加载到表 A 的功能,并且可以保证在此期间只有唯一的进程加载到该表中。
一旦删除触发器,就无法保证插入到 tableB 中。您唯一的希望是所有可能插入表 A 的程序(您真的了解所有这些吗?) 坚持二次插入表 B。这是“通过公司策略实现数据完整性”,而不是通过 Oracle 强制执行的数据完整性。
我认为这种方法取决于您对 tableB 中数据状态的关心程度。
我不会走表 api (TAPI) 的路线,它现在强制通过一些处理逻辑的 pl/sql api 进行任何/所有操作。根据我的经验,这些几乎总是缓慢且有问题的。
If you want to guarantee that you'll have a record inserted into tableB when something inserts into tableA, then keep the trigger. You can disable if bulk loading into tableA and can guarantee you'll have the only process loading into that table during that time.
As soon as you remove the trigger, you have NO guarantees about inserts into tableB. Your only hope is that any and all programs that may insert into tableA (do you really know all of these?) adhere to the secondary insert into tableB. This is "data integrity via company policy", not data integrity enforced via Oracle.
This approach depends on how much you care about the state of the data in tableB I suppose.
I would NOT go the route of table apis (TAPIs), which now force any/all operations through some pl/sql api that handles the logic. These almost always tend to be slow and buggy in my experience.
在 DDL 中,您可以使用 ALTER TRIGGER 或 ALTER TABLE 禁用触发器。
要在运行时执行此操作,您必须使用动态 SQL,并且运行过程的模式必须拥有该表或具有必要的权限。
有关启用/禁用触发器的详细信息,请参阅 http:// /download.oracle.com/docs/cd/B28359_01/server.111/b28310/general004.htm
In DDL You can disable a trigger with ALTER TRIGGER or ALTER TABLE.
To do this at runtime, you would have to use dynamic SQL and the schema in which the procedure is running must own the table or otherwise have the necessary privileges.
For more info on enabling/disabling triggers, see http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/general004.htm