監控oracle的觸發器語句(轉)
監控oracle的觸發器語句(轉)[@more@]首先建一個日誌表,然後分別建立3個觸發器
create table EVENTLOG
(
EVENTNAME VARCHAR2(20) not null,
OPER_TIME DATE default sysdate,
INST_NUM NUMBER,
DB_NAME VARCHAR2(50),
SRV_ERROR NUMBER,
USERNAME VARCHAR2(30),
OBJ_TYPE VARCHAR2(20),
OBJ_NAME VARCHAR2(30),
OBJ_OWNER VARCHAR2(30)
)
create or replace trigger trig_ddl
after create or alter or drop on database
declare
event varchar2(20);
typ varchar(20);
name varchar(30);
owner varchar(30);
begin
--讀取DDL事件屬性
event:=sysevent;
typ:=dictionary_obj_type;
name:=dictionary_obj_name;
owner:=dictionary_obj_owner;
insert into eventlog(eventname,obj_type,obj_name,obj_owner)
values(event,typ,name,owner);
end ;
create or replace trigger trig_shutdown
before LOGOFF or shutdown on database
declare
event varchar2(20);
instance number;
dbname varchar(50);
user varchar(30);
begin
event:=sysevent;
if event = 'LOGOFF' then
user:=login_user;
insert into eventlog(eventname,username)
values(event,user);
else
instance:=instance_num;
dbname:=database_name;
insert into eventlog(eventname,inst_num,db_name)
values(event,instance,dbname);
end if;
end ;
create or replace trigger trig_startup
after LOGON or STARTUP or SERVERERROR on database
declare
event varchar2(20);
instance number;
dbname varchar(50);
err_num number;
user varchar(30);
begin
event:=sysevent;
if event = 'LOGON' then
user:=login_user;
insert into eventlog(eventname,username)
values(event,user);
elsif event = 'SERVERERROR' then
err_num:=server_error(1);
insert into eventlog(eventname,srv_error)
values(event,err_num);
else
instance:=instance_num;
dbname:=database_name;
insert into eventlog(eventname,inst_num,db_name)
values(event,instance,dbname);
end if;
end ;
create table EVENTLOG
(
EVENTNAME VARCHAR2(20) not null,
OPER_TIME DATE default sysdate,
INST_NUM NUMBER,
DB_NAME VARCHAR2(50),
SRV_ERROR NUMBER,
USERNAME VARCHAR2(30),
OBJ_TYPE VARCHAR2(20),
OBJ_NAME VARCHAR2(30),
OBJ_OWNER VARCHAR2(30)
)
create or replace trigger trig_ddl
after create or alter or drop on database
declare
event varchar2(20);
typ varchar(20);
name varchar(30);
owner varchar(30);
begin
--讀取DDL事件屬性
event:=sysevent;
typ:=dictionary_obj_type;
name:=dictionary_obj_name;
owner:=dictionary_obj_owner;
insert into eventlog(eventname,obj_type,obj_name,obj_owner)
values(event,typ,name,owner);
end ;
create or replace trigger trig_shutdown
before LOGOFF or shutdown on database
declare
event varchar2(20);
instance number;
dbname varchar(50);
user varchar(30);
begin
event:=sysevent;
if event = 'LOGOFF' then
user:=login_user;
insert into eventlog(eventname,username)
values(event,user);
else
instance:=instance_num;
dbname:=database_name;
insert into eventlog(eventname,inst_num,db_name)
values(event,instance,dbname);
end if;
end ;
create or replace trigger trig_startup
after LOGON or STARTUP or SERVERERROR on database
declare
event varchar2(20);
instance number;
dbname varchar(50);
err_num number;
user varchar(30);
begin
event:=sysevent;
if event = 'LOGON' then
user:=login_user;
insert into eventlog(eventname,username)
values(event,user);
elsif event = 'SERVERERROR' then
err_num:=server_error(1);
insert into eventlog(eventname,srv_error)
values(event,err_num);
else
instance:=instance_num;
dbname:=database_name;
insert into eventlog(eventname,inst_num,db_name)
values(event,instance,dbname);
end if;
end ;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10617731/viewspace-962928/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 語句觸發器觸發器
- 禁止oracle表的觸發器triggerOracle觸發器
- Oracle行轉列、列轉行的Sql語句總結OracleSQL
- Oracle開發基礎-觸發器Oracle觸發器
- ORACLE常用語句:Oracle
- 如何匯出儲存過程、函式、包和觸發器的定義語句?如何匯出表和索引的建立語句?儲存過程函式觸發器索引
- oracle中的條件語句Oracle
- 動態監控input的值的變化 賦值value觸發賦值
- Oracle 建立序列語句Oracle
- Oracle基本SQL語句OracleSQL
- 監控索引的使用(轉)索引
- oracle儲存過程和觸發器Oracle儲存過程觸發器
- mysql觸發器實時檢測一條語句進行備份刪除MySql觸發器
- ORACLE 資料庫 查詢語句與DML語句Oracle資料庫
- ORACLE監控之OSW部署Oracle
- SQL查詢語句 (Oracle)SQLOracle
- 6. Oracle開發和應用—6.3. 基本SQL語句—6.3.4. select語句OracleSQL
- 監聽ORM背後的sql語句。ORMSQL
- Zabbix如何監控Oracle的告警日誌Oracle
- 轉轉支付通道監控系統的搭建
- Zabbix透過Orabbix監控OracleOracle
- oracle檢視物件DDL語句Oracle物件
- oracle資料庫常用語句Oracle資料庫
- 【LOB】Oracle lob管理常用語句Oracle
- oracle語句練習--初級Oracle
- ORACLE多表關聯UPDATE語句Oracle
- Oracle資料庫語句大全Oracle資料庫
- 列出oracle dbtime得sql語句OracleSQL
- Oracle vs PostgreSQL,研發注意事項(13) - UPDATE語句OracleSQL
- 6. Oracle開發和應用—6.4. PL/SQL語法—6.4.4. 條件語句(分支語句)OracleSQL
- 使用zabbix監控oracle的後臺日誌Oracle
- 【TABLE】Oracle監控異常的表設計Oracle
- Oracle exp dmp包檔案轉化為insert語句,extract dmp to sqlfileOracleSQL
- Oracle常用的系統查詢語句整理Oracle
- Oracle中獲取TABLE的DDL語句的方法Oracle
- ORACLE OGG運維及日常監控Oracle運維
- ORACLE結構化查詢語句Oracle
- 後臺執行SQL語句(oracle)SQLOracle
- Oracle SQL精妙SQL語句講解OracleSQL