Oracle常用指令碼 監控DDL

2021-05-24 00:11:37 字數 1950 閱讀 5499

create table db_ddl

(ddl_time                       varchar2(30),

session_id                     number,

os_user                        varchar2(200),

ip_address                     varchar2(200),

terminal                       varchar2(200),

host                           varchar2(200),

user_name                      varchar2(30),

ddl_type                       varchar2(30),

object_type                    varchar2(18),

owner                          varchar2(30),

object_name                    varchar2(128),

sql_text                       varchar2(4000))

/create or replace trigger tri_ddl

after

ddlon schema

declare

sql_text    ora_name_list_t;

i           number(10);

state_sql   varchar2 (4000);

begin

begin

for i in 1 .. ora_sql_txt (sql_text)

loop

state_sql := state_sql || sql_text (i);

end loop;

exception

when others then

sp_sqllog('tri_ddl error:' || ora_dict_obj_name || sqlerrm);

end;

state_sql := substrb (state_sql, 1, 4000);

if not state_sql like 'alter%compile%' then

insert into db_ddl

(ddl_time,

session_id,

os_user,

ip_address,

terminal,

host,

user_name, ddl_type,

object_type, owner,

object_name, sql_text

)values (to_char (sysdate, 'yyyymmddhh24miss'),

sys_context ('userenv', 'sessionid'),

sys_context ('userenv', 'os_user'),

sys_context ('userenv', 'ip_address'),

sys_context ('userenv', 'terminal'),

sys_context ('userenv', 'host'),

ora_login_user, ora_sysevent,

ora_dict_obj_type, ora_dict_obj_owner,

ora_dict_obj_name, state_sql

);end if;

exception

when others

then

sp_sqllog('tri_ddl error:' || sqlerrm);

end;

/

Oracle監控Sql指令碼

spool d 10 10.log prompt 192.168.10.10 wcm03 分析 prompt 分析時間 select sysdate from dual prompt 資料庫例項 select name from v database prompt 檢查資料檔案的狀態記錄狀態不是 o...

Oracle 常用指令碼

查詢當前連線數 select count from v session select username,machine,program,status,count machine as 連線數量 from v session where username cotsdev group by userna...

oracle 常用指令碼

substr 取得字串中指定起始位置和長度的字串 instr 判斷其是否含有指定的字元 replace 替換字元 create table table 1 as select from table 2 where 1 0 建表只複製表結構 表新增預設值 alter table table 1 mod...