oracle 触发器
----触发器---
---创建中间插入的表
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 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;
---查询登陆信息
select * from session_history q where q.username not in ('SYS');
-------触发器针对对数据库表做修改-------
1.创建存触发触发器数据的表
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 select,update,insert on bap.trigger_test to test;
4.测试触发器是否生效
update BAP.T_test qq set qq.bnk_no='' where BNK_CD='888';
5.验证是否有数据入表
select * from test.trigger_test;
6.其他操作
--DROP trigger test.T_test_trigger
select * from dba_triggers ww where ww.owner=TEST;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了