创建一个监听多个表的全局触发器
Posted
技术标签:
【中文标题】创建一个监听多个表的全局触发器【英文标题】:Creating a global trigger that listens to multiple tables 【发布时间】:2012-02-13 20:59:31 【问题描述】:我想在 Oracle 11g 中创建一个全局触发器。可用于审计大约 100 个表。多个表可以触发单个触发器。如果是,那么我该如何实现呢?
【问题讨论】:
【参考方案1】:我想在 oracle 11g 中创建一个全局触发器,可用于审计大约 100 个表
您是否有理由要重新发明***?为什么不使用 Oracle 的内置审计功能?
Oracle Base 提供了一些关于如何开始审计的基本信息:
可以通过设置 AUDIT_TRAIL 静态参数来启用审计,该参数具有以下允许值。
AUDIT_TRAIL = none | os | db | db,extended | xml | xml,extended
以下列表提供了每个设置的说明:
none or false - Auditing is disabled.
db or true - Auditing is enabled, with all audit records stored in the database audit trial (SYS.AUD$).
db,extended - As db, but the SQL_BIND and SQL_TEXT columns are also populated.
xml- Auditing is enabled, with all audit records stored as XML format OS files.
xml,extended - As xml, but the SQL_BIND and SQL_TEXT columns are also populated.
os- Auditing is enabled, with all audit records directed to the operating system's audit trail.
要启用对数据库审计跟踪的审计,启用对 db 的审计
SQL> ALTER SYSTEM SET audit_trail=db,extended SCOPE=SPFILE;
System altered.
关闭并重新启动数据库
SQL> SHUTDOWN
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP
ORACLE instance started.
现在审核SELECTS
、INSERTS
、UPDATES
、DELETES
由用户cube
执行此操作:
CONNECT sys/password AS SYSDBA
AUDIT ALL BY cube BY ACCESS;
AUDIT SELECT TABLE, UPDATE TABLE, INSERT TABLE, DELETE TABLE BY cube BY ACCESS;
可以通过查询DBA_AUDIT_TRAIL
调出审核日志
进一步阅读:
Auditing Fine grained auditing Configuring and administering auditing【讨论】:
以上是关于创建一个监听多个表的全局触发器的主要内容,如果未能解决你的问题,请参考以下文章