oracle视图触发器问题

hemingwang0902 hemingwang0902 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题是这样的我现在有两个表 table_a 和 table_b, 还有一个视图 view_a, 表和视图的结构如下

-- Create table
create table table_a
(
a number,
b varchar2(30),
c varchar2(30)
);
-- Create/Recreate primary, unique and foreign key constraints
alter table table_a
add constraint PK_table_a primary key (A);

===================================================================

-- Create table
create table table_b
(
a number,
b varchar2(30),
c varchar2(30)
);
-- Create/Recreate primary, unique and foreign key constraints
alter table table_b
add constraint PK_table_b primary key (A);

===================================================================

create view view_a as select * from table_b;


但我对 table_b 没有任何操作权限,只对 table_a 和 view_a 有操作权限, 我现在要实现的功能是 table_b 中的数据有变化(inser, update, delete)时,就将 table_a 中的记录对应更新, 于是建立了下面这个触发器:

create or replace trigger trg_insurance
instead of update or insert or delete on view_a
begin
if inserting then
insert into table_a(a,b,c) values(:new.a,:new.b,:new.c);
elsif updating then
if (:new.b=1) then
insert into table_a(a,b,c) values(:new.a,:new.b,:new.c);
elsif (:new.b=0) then
delete from table_a where a=:old.a;
end if;
elsif deleting then
delete from table_a where a=:old.a;
end if;
end;

现在问题就来了, 对方(有权限操作table_b的)执行

//将 insert 改为对应的 update, delete 语句时一样不会触发
insert into table_b values(1,'1','1');
commit;

时,并没有触发触发器 trg_insurance, 而只有执行

//将 insert 改为对应的 update, delete 语句时也会执行触发器trg_insurance
insert into view_a values(1,'1','1');
commit;

时,触发器 trg_insurance 才会执行.

也就是说只有直接在 view_a 上作对应的操作时触发器 trg_insurance 才会被执行, 而直接操作实体表 table_b 时,触发器无法被执行, 请问我该怎么创建触发器才能在直接对实体表的数据进行修改(insert, update, delete)时,才能将触发器 trg_insurance 触发。(特别注意的是,我对 table_b 没有任何权限, 所以不可能直接在 table_b 上创建触发器)
...全文
评论 7
收藏 已收藏
分享
返回顶部