createtable
trig_sql(
lt date
notnull
primary
key,
sid
number
, serial#
number
, username
varchar2(30
), osuser
varchar2(64
), machine
varchar2(32
), terminal
varchar2(16
), program
varchar2(64
), sqltext
varchar2(2000
), status
varchar2(30
), client_ip
varchar2(60
),);
createindex idx_time on trig_sql (lt);
in_first_page_other:我們要監控的表
createorreplace
trigger
pri_test
after
insert
orupdate
ordelete
onin_first_page_other
foreach row
declare
pragma autonomous_transaction;
begin
if inserting then
insert
into
trig_sql
select
sysdate,s.sid, s.serial#, s.username, s.osuser,
s.machine, s.terminal, s.program, q.sql_text line,
'insert',
sys_context(
'userenv
','ip_address')
from
v$sql q, v$session s
where s.audsid=(select userenv('
sessionid
') from
dual)
and s.prev_sql_addr=
q.address
and s.prev_hash_value =
q.hash_value;
commit
; elsif deleting
then
insert
into
trig_sql
select
sysdate,s.sid, s.serial#, s.username, s.osuser,
s.machine, s.terminal, s.program, q.sql_text line,
'delete',
sys_context(
'userenv
','ip_address')
from
v$sql q, v$session s
where s.audsid=(select userenv('
sessionid
') from
dual)
and s.prev_sql_addr=
q.address
and s.prev_hash_value =
q.hash_value;
commit
; elsif updating
then
insert
into
trig_sql
select
sysdate,s.sid, s.serial#, s.username, s.osuser,
s.machine, s.terminal, s.program, q.sql_text line,
'update',
sys_context(
'userenv
','ip_address')
from
v$sql q, v$session s
where s.audsid=(select userenv('
sessionid
') from
dual)
and s.prev_sql_addr=
q.address
and s.prev_hash_value =
q.hash_value;
commit
;
endif
;end;
對要監控的表進行操作後,可以查到日誌資訊
selectt.lt 操作時間,
t.sid 會話唯一標識,
t.serial# 唯一序列號,
t.username 資料庫使用者,
t.osuser 客戶端作業系統使用者名稱,
t.machine 客戶端全名,
t.terminal 客戶端名,
t.program 客戶端應用程式,
t.sqltext sql文字,
t.status 增刪改,
t.client_ip ip位址
from trig_sql t where
to_char(t.lt,
'yyyy-mm-dd hh24:mi:ss
')
between to_char(to_date('
2018-06-01 16:42:10
','yyyy-mm-dd hh24:mi:ss
'),'
yyyy-mm-dd hh24:mi:ss')
and to_char(to_date('
2018-06-01 16:42:11
','yyyy-mm-dd hh24:mi:ss
'),'
yyyy-mm-dd hh24:mi:ss
')
ORACLE觸發器 行級觸發器
行級觸發器 本章介紹行級觸發器機制。大部分例子以insert出發器給出,行級觸發器可從insert update delete語句觸發。1 介紹 觸發器是儲存在資料庫已編譯的儲存過程,使用的語言是pl sql,用編寫儲存過程一樣的方式編寫和編譯觸發器。下面在sql plus會話中建立和示例乙個簡單的...
Oracle表級觸發器語句
孟子辰 2016 12 04 06 22 示例 一 只有在每個月的10日才允許辦理,新員工入職與離職,其他時間不允許增加和刪除員工資料 建立表 create table myemp as select from emp 建立觸發器 create or replace trigger changemy...
oracle操作基表觸發器
建立乙個測試表 create tablecreate table test a number,b number,c number,id number not null alter table test add constraint test primary id primary key id 看一看...