[英]I want that the studentid table field with zreo value is not insert,i do this by using trigger but it still allow to insert them
[英]Hello Experts! I want to insert value to second table instead of first table using trigger
你能帮我完成我的工作吗? 因为我对 Oracle 技术比较陌生。
我想使用触发器将值插入第二个表而不是第一个表。 如果我尝试在第一个表中插入任何值,它将插入到第二个表而不是第一个表中。 请帮我解决一下这个。 谢谢大家。 这是示例数据
创建表table_1(id号); 创建表table_2(id号); 我将在 table_1 中插入值,如 insert into table_1 values(10);
select * 来自 table_2;
10
select * 来自 table_1;
基本上,在所有情况下您都将table_1
为空,并且所有数据都存储在table_2
中。 为此,您需要两个触发器,因为行级触发器(“对于每一行”)无法从其基表中删除数据(因为该表正在发生变化)。
示例表:
SQL> create table table_1(id number);
Table created.
SQL> create table table_2(id number);
Table created.
将数据“重定向”到table_2
的行级触发器:
SQL> create or replace trigger trg_bi_1
2 before insert on table_1
3 for each row
4 begin
5 insert into table_2 (id) values (:new.id);
6 end;
7 /
Trigger created.
从table_1
中删除数据的语句级触发器:
SQL> create or replace trigger trg_ai_1
2 after insert on table_1
3 begin
4 delete from table_1;
5 end;
6 /
Trigger created.
测试:
SQL> insert into table_1 (id) values (10);
1 row created.
SQL> select * from table_1;
no rows selected
SQL> select * from table_2;
ID
----------
10
SQL>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.