oracle trigger

----Trigger---
---Create a table for intermediate inserts

create table session_history tablespace bap_data
as (select sid,username,program,machine,'000.000.000.000'ipadd,sysdate moditime from v$session where 0=1);

 

---Create trigger---Trigger as long as you log in to the database

 

create or replace trigger on_logon_trigger
 after logon on database
 begin
insert into session_history select sid,username,program,machine,sys_context('userenv','ip_address'),sysdate from v$session where audsid = userenv('sessionid');
end;

 

---Query login information
select * from session_history q where q.username not in ('SYS');

 

 

------- Triggers modify database tables -------
1. Create a table that stores trigger trigger data

 create table test.trigger_test tablespace test_data as (select sid,username,program,machine,'000.000.000.000'ipadd,sysdate moditime from v$session where 0=1);

 2.创建对应触发器
create or replace trigger test.T_test_trigger
 before delete or update on test.T_test
 for each row
begin
 insert into test.trigger_test select sid,username,program,machine,sys_context('userenv','ip_address'),sysdate from v$session where audsid = userenv('sessionid');
 end;

 3. Grant permission to the trigger owner
grant select, update, insert on bap.trigger_test to test;

4. Test whether the trigger is effective
 update BAP.T_test qq set qq.bnk_no='' where BNK_CD='888';

5. Verify whether there is data in the table
 select * from test.trigger_test;

6.其他操作
--DROP trigger  test.T_test_trigger
select * from dba_triggers ww where ww.owner=TEST;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324855332&siteId=291194637