场景:
触发器 ,数据插入表1后,同时把数据插入表2
(sql语句在plsql亲测过,可行。这里每次插入表1 都会把表1的数据全部在插入表2,数据会重复)
--表1 create table student ( id VARCHAR2(32) not null, name VARCHAR2(8) not null, age NUMBER(13,3), birthday DATE, address VARCHAR2(200) ) --表2 create table student_two ( id VARCHAR2(32) not null, name VARCHAR2(8) not null, age NUMBER(13,3), birthday DATE, address VARCHAR2(200) ) --触发器 ,插入表1后,同时把数据插入表2 CREATE OR REPLACE TRIGGER stu_tri AFTER INSERT ON student BEGIN INSERT INTO student_two (ID, NAME, AGE, BIRTHDAY, ADDRESS) SELECT ID, NAME, AGE, BIRTHDAY, ADDRESS FROM STUDENT ; END stu_tri ; delete from student; delete from student_two; commit; insert into STUDENT (ID, NAME, AGE, BIRTHDAY, ADDRESS) values ('1', '张三', 11.000, to_date('01-08-2010', 'dd-mm-yyyy'), '广州'); insert into STUDENT (ID, NAME, AGE, BIRTHDAY, ADDRESS) values ('2', '李四', 9.000, to_date('11-06-2012', 'dd-mm-yyyy'), '深圳'); insert into STUDENT (ID, NAME, AGE, BIRTHDAY, ADDRESS) values ('3', '王五', 7.000, to_date('05-07-2014', 'dd-mm-yyyy'), '上海'); commit; select * from student order by id; select * from student_two order by id;
查询效果图: