批量上传并触发
关于批量绑定和触发器的几个问题 (Oracle 10g)
1) 批量绑定时行级触发器会执行吗?
2)如果是,那么是否有任何选项可以仅抑制批量绑定的执行?
3)如果没有的话,有没有办法在批量绑定中执行行级触发器?
4) 如果行级触发器执行批量绑定,性能会受到影响吗?
Few of questions for bulk-bind and trigger (Oracle 10g)
1) Will row level trigger execute in case of bulk binding ?
2) If yes then, is there any option to surpress the execution only for bulk binding ?
3) If no then, is there a way to execute row level trigger in bulk binding ?
4) Will performance hamper in case row level trigger executes for bulk binding ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当执行批量绑定插入时,触发器仍然启用并触发。您本质上无法阻止这种情况,但是您当然可以将自己的逻辑放入触发器和执行批量插入的代码中,如下所示...
在包规范中:
在触发器中:
在调用代码中:
Triggers are still enabled and fired when bulk-bind inserts are performed. There is nothing intinsic you can do to stop that, but of course you can put your own logic in the trigger and the code that does the bulk insert like as follows...
In a package specification:
In the trigger:
In the calling code:
触发器在 SQL 引擎内执行。批量绑定通过减少调用/语句的数量来影响调用语言(pl/sql 或任何 OCI 语言)调用 SQL 引擎的方式,但不应绕过任何触发器。
(想象一下,您使用触发器向数据库添加验证、日志记录或其他约束,但第三方应用程序只需使用批量操作即可绕过它 - 这将导致数据损坏和安全问题)。
您的语句级触发器应该触发一次。
您可以通过在执行其他操作之前检查内存中的会话变量来“禁用”触发器,并在批量操作之前显式设置它。
行级触发器仍然会在每行的基础上触发,这可能会产生更大的影响。
Triggers execute within the SQL engine. Bulk-binding impacts the way that the calling language (pl/sql or any OCI language) calls the SQL engine, by reducing the number of calls/statements, but should not bypass any triggers.
(Imagine you have used a trigger to add validation, logging or other constraint to a database, but a third-party application would bypass it simply through using a bulk operation - this would be a recipe for data corruption and security issues).
Your statement level trigger should fire once.
You could 'disable' your trigger by making it check an in-memory session variable before doing anything else, and explicitly setting it before a bulk operation.
Row level triggers would still fire on a per-row basis, which could have a lot more impact.