TRIGGERS插入同一张表-PLSQL [英] TRIGGERS insert same table - PLSQL
本文介绍了TRIGGERS插入同一张表-PLSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题:
我必须改变这样的东西
在同一表格中放入
我尝试了触发器,但是我遇到了变异问题,我无法控制插入,但是我需要对值大于1的每一行执行此操作. 有任何建议吗?
I've tried triggers but I have mutating issues, I have no control about the inserts but I need to do that for every row with value larger than 1. Any sugestions?
推荐答案
您需要使用视图而不是触发器.
You need to use view and instead of trigger.
- 创建表
create table testing_trig (c char(1), i integer);
- 创建视图
create or replace view testing_trig_view as select * from testing_trig;
- 创建触发器
- Creating table
create table testing_trig (c char(1), i integer);
- Creating view
create or replace view testing_trig_view as select * from testing_trig;
- Creating trigger
CREATE OR REPLACE TRIGGER testing_trg
INSTEAD OF INSERT
ON testing_trig_view
BEGIN
FOR i IN 1 .. :NEW.i
LOOP
INSERT INTO testing_trig VALUES (:NEW.c, 1);
END LOOP;
END;
/
- 插入视图
insert into testing_trig_view values ('A', 3);
- 验证
SQL> select * from testing_trig;
C I
- ----------
A 1
A 1
A 1
这篇关于TRIGGERS插入同一张表-PLSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文