Create a trigger TO monitoring DDL
--1、CREATE TABLESPACE、USER AND GRANT ROLE TO USER-----------
DROP TABLESPACE YGZHOU INCLUDING CONTENTS AND DATAFILES;
CREATE TABLESPACE YGZHOU DATAFILE '/data1/stream/ygzhou01/datafile/ygzhou01.dbf' SIZE 10M AUTOEXTEND ON NEXT 5m;
CREATE USER YGZHOU IDENTIFIED BY YGZHOU DEFAULT TABLESPACE YGZHOU;
GRANT DBA TO YGZHOU;
ALTER USER YGZHOU DEFAULT ROLE ALL;
GRANT CREATE SESSION TO YGZHOU;
GRANT UNLIMITED TABLESPACE TO YGZHOU;
------------------------------------------------------------
--GRANT SELECT ON SYS.V_$SQL TO YGZHOU;
--GRANT SELECT ON SYS.V_$SQL_BIND_DATA TO YGZHOU;
--GRANT SELECT ON SYS.V_$SQL_CURSOR TO YGZHOU;
--GRANT SELECT ON SYS.V_$SESSION TO YGZHOU;
--GRANT CREATE TRIGGER TO YGZHOU;
--2、CREATE TABLE ------------------------------------------
DROP TABLE YGZHOU.DDL_LOG CASCADE CONSTRAINTS;
DROP TABLESPACE YGZHOU INCLUDING CONTENTS AND DATAFILES;
CREATE TABLESPACE YGZHOU DATAFILE '/data1/stream/ygzhou01/datafile/ygzhou01.dbf' SIZE 10M AUTOEXTEND ON NEXT 5m;
CREATE USER YGZHOU IDENTIFIED BY YGZHOU DEFAULT TABLESPACE YGZHOU;
GRANT DBA TO YGZHOU;
ALTER USER YGZHOU DEFAULT ROLE ALL;
GRANT CREATE SESSION TO YGZHOU;
GRANT UNLIMITED TABLESPACE TO YGZHOU;
------------------------------------------------------------
--GRANT SELECT ON SYS.V_$SQL TO YGZHOU;
--GRANT SELECT ON SYS.V_$SQL_BIND_DATA TO YGZHOU;
--GRANT SELECT ON SYS.V_$SQL_CURSOR TO YGZHOU;
--GRANT SELECT ON SYS.V_$SESSION TO YGZHOU;
--GRANT CREATE TRIGGER TO YGZHOU;
--2、CREATE TABLE ------------------------------------------
DROP TABLE YGZHOU.DDL_LOG CASCADE CONSTRAINTS;
CREATE TABLE YGZHOU.DDL_LOG
(
DB_NAME VARCHAR2(20 BYTE),
USERNAME VARCHAR2(20 BYTE),
CLIENT_IP VARCHAR2(20 BYTE),
DDL_SCRIPTS VARCHAR2(4000 BYTE),
RECORD_TIME DATE DEFAULT SYSDATE
);
--3、CREATE TRIGGER----------------------------------------
DROP TRIGGER YGZHOU.DDL_LOG;
CREATE OR REPLACE TRIGGER YGZHOU.DDL_LOG AFTER DDL ON DATABASE
DECLARE
SQL_TEXT ORA_NAME_LIST_T;
SQL_STMT VARCHAR2(4000);
-- v_DB_ID VARCHAR2(20);
(
DB_NAME VARCHAR2(20 BYTE),
USERNAME VARCHAR2(20 BYTE),
CLIENT_IP VARCHAR2(20 BYTE),
DDL_SCRIPTS VARCHAR2(4000 BYTE),
RECORD_TIME DATE DEFAULT SYSDATE
);
--3、CREATE TRIGGER----------------------------------------
DROP TRIGGER YGZHOU.DDL_LOG;
CREATE OR REPLACE TRIGGER YGZHOU.DDL_LOG AFTER DDL ON DATABASE
DECLARE
SQL_TEXT ORA_NAME_LIST_T;
SQL_STMT VARCHAR2(4000);
-- v_DB_ID VARCHAR2(20);
--CREATED BY Ygzhou518
--Date:2012-03-13
--Date:2012-03-13
BEGIN
SQL_STMT:='DB ';
-- v_DB_ID:='YGZHOUDB'; --The value must be registered in table DBMS.INSTANCE_INFO.
FOR I IN 1..ORA_SQL_TXT(SQL_TEXT) LOOP
IF LENGTH(SQL_STMT)<3800 THEN
SQL_STMT := SQL_STMT||SQL_TEXT(I);
END IF;
END LOOP;
IF LENGTH(SQL_STMT)<3800 THEN
SQL_STMT := SQL_STMT||SQL_TEXT(I);
END IF;
END LOOP;
INSERT INTO YGZHOU.DDL_LOG (DB_NAME,USERNAME,CLIENT_IP,RECORD_TIME,DDL_SCRIPTS)
SELECT
--v_DB_ID,
'YGZHOUDB',ORA_LOGIN_USER,SYS_CONTEXT('USERENV','IP_ADDRESS'),SYSDATE, SQL_STMT FROM DUAL;
END ;
/
-------------------------------------------------------------------------------------------------
SELECT
--v_DB_ID,
'YGZHOUDB',ORA_LOGIN_USER,SYS_CONTEXT('USERENV','IP_ADDRESS'),SYSDATE, SQL_STMT FROM DUAL;
END ;
/
-------------------------------------------------------------------------------------------------
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24867586/viewspace-718434/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 禁止DDL執行的trigger
- 控制DDL許可權及紀錄DDL操作的Trigger
- SQLite建立觸發器 CREATE TRIGGERSQLite觸發器
- ORA-01031 CREATE TRIGGER ON DATABASEDatabase
- trigger 'SYS.GGS_DDL_TRIGGER_BEFORE' is invalid and failed re-validationAI
- oracle trigger觸發器審計schema物件的變更ddlOracle觸發器物件
- 透過trigger禁止使用者刪除或修改等DDL操作
- 通過trigger禁止使用者刪除或修改等DDL操作
- 使用after create 建立trigger記錄procedure PL/SQL程式碼變更SQL
- STREAMS MONITORING
- Column Monitoring
- Oracle:TABLE MONITORINGOracle
- oracle index monitoringOracleIndex
- Monitoring WebSite StateWeb
- Oracle EBS Monitoring ScriptsOracle
- Monitoring an SAP instance
- sql monitoring實驗SQL
- Monitoring Core Process...
- Monitoring Open and Cached Cursors
- Monitoring RMAN Backups
- Mysql TriggerMySql
- jQuery trigger()jQuery
- ±±oracle trigger±±Oracle
- sql triggerSQL
- Go: sysmon, Runtime MonitoringGo
- Oracle Real Time SQL MonitoringOracleSQL
- Monitoring Open and Cached Cursors(zt)
- Test Oracle triggerOracle
- Oracle9i Table monitoring 及10g table預設monitoring屬性Oracle
- PostgreSQL DBA(77) - Locks(Lock Monitoring)SQL
- 對索引開啟monitoring方法索引
- Top DBA Shell Scripts for Monitoring the DatabaseDatabase
- Monitoring Open and Cached Cursors(轉載)
- Java Monitoring, Management and Troubleshooting ToolsJava
- Oracle trigger問題Oracle
- 配置GoldenGate啟動DDL支援同步DDL操作Go
- ddl練習
- Monitoring Tempdb in SQL Server 2005SQLServer