select * from A
--话题资源表
INSERT INTO B (suser,scontent,createTime, nispublic, smoduleId)
VALUES ('A表中的screateUser','A表中的nid','A表中的screatetime',0,'report')
--话题信息表
INSERT INTO C (scontent, nsource, suser, platform, stitle)
VALUES ('A表中的nreport', 'B的nid', 'A表中的screateUser','PC-Chrome', '报告话题' ) ,
求大神指导!
oracle,触发器或者存储过程实现,表A插入一条记录,表B和表C自动插入一条记录,详情如下
答案:2 悬赏:0 手机版
解决时间 2021-02-06 02:14
- 提问者网友:玫瑰园
- 2021-02-05 12:56
最佳答案
- 五星知识达人网友:鱼忧
- 2021-02-05 13:39
代码如下:
CREATE OR REPLACe TRIGGER tri_aft_ins_a
AFTER INSERT ON a
FOR EACH ROW
DECLARE
BEGIN
INSERT INTO B
(suser, scontent, createTime, nispublic, smoduleId)
VALUES
(:NEW.screateUser, :NEW.nid, :new.screatetime, 0, 'report');
INSERT INTO C
(scontent, nsource, suser, platform, stitle)
VALUES
(:new.nreport, :new.nid, :new.screateUser, 'PC-Chrome', '报告话题');
END tri_aft_ins_a;
/模拟测试:
SQL> CREATE TABLE a (screateUser VARCHAr(20),nid VARCHAr2(20),screatetime VARCHAr2(20),nreport VARCHAr2(20));
Table created
SQL> CREATE TABLE b (suser VARCHAr(20),scontent VARCHAr(20),createTime VARCHAr(20), nispublic VARCHAr(20), smoduleId VARCHAr(20));
Table created
SQL> CREATE TABLE c (scontent VARCHAr(20), nsource VARCHAr(20), suser VARCHAr(20), platform VARCHAr(20), stitle VARCHAr(20));
Table created
SQL>
SQL> CREATE OR REPLACE TRIGGER tri_aft_ins_a
2 AFTER INSERT ON a
3 FOR EACH ROW
4 DECLARE
5 BEGIN
6 INSERT INTO B
7 (suser, scontent, createTime, nispublic, smoduleId)
8 VALUES
9 (:NEW.screateUser, :NEW.nid, :new.screatetime, 0, 'report');
10
11 INSERT INTO C
12 (scontent, nsource, suser, platform, stitle)
13 VALUES
14 (:new.nreport, :new.nid, :new.screateUser, 'PC-Chrome', '报告话题');
15 END tri_aft_ins_a;
16 /
Trigger created
SQL> INSERT INTO a VALUES(1,2,3,4);
1 row inserted
SQL> SELECT * FROM b;
SUSER SCONTENT CREATETIME NISPUBLIC SMODULEID
-------------------- -------------------- -------------------- -------------------- --------------------
1 2 3 0 report
SQL> SELECt * FROM c;
SCONTENT NSOURCE SUSER PLATFORM STITLE
-------------------- -------------------- -------------------- -------------------- --------------------
4 2 1 PC-Chrome 报告话题
SQL> INSERT INTO a VALUES(5,6,7,8);
1 row inserted
SQL> SELECt * FROM b;
SUSER SCONTENT CREATETIME NISPUBLIC SMODULEID
-------------------- -------------------- -------------------- -------------------- --------------------
1 2 3 0 report
5 6 7 0 report
SQL> SELECt * FROM c;
SCONTENT NSOURCE SUSER PLATFORM STITLE
-------------------- -------------------- -------------------- -------------------- --------------------
4 2 1 PC-Chrome 报告话题
8 6 5 PC-Chrome 报告话题
SQL>
CREATE OR REPLACe TRIGGER tri_aft_ins_a
AFTER INSERT ON a
FOR EACH ROW
DECLARE
BEGIN
INSERT INTO B
(suser, scontent, createTime, nispublic, smoduleId)
VALUES
(:NEW.screateUser, :NEW.nid, :new.screatetime, 0, 'report');
INSERT INTO C
(scontent, nsource, suser, platform, stitle)
VALUES
(:new.nreport, :new.nid, :new.screateUser, 'PC-Chrome', '报告话题');
END tri_aft_ins_a;
/模拟测试:
SQL> CREATE TABLE a (screateUser VARCHAr(20),nid VARCHAr2(20),screatetime VARCHAr2(20),nreport VARCHAr2(20));
Table created
SQL> CREATE TABLE b (suser VARCHAr(20),scontent VARCHAr(20),createTime VARCHAr(20), nispublic VARCHAr(20), smoduleId VARCHAr(20));
Table created
SQL> CREATE TABLE c (scontent VARCHAr(20), nsource VARCHAr(20), suser VARCHAr(20), platform VARCHAr(20), stitle VARCHAr(20));
Table created
SQL>
SQL> CREATE OR REPLACE TRIGGER tri_aft_ins_a
2 AFTER INSERT ON a
3 FOR EACH ROW
4 DECLARE
5 BEGIN
6 INSERT INTO B
7 (suser, scontent, createTime, nispublic, smoduleId)
8 VALUES
9 (:NEW.screateUser, :NEW.nid, :new.screatetime, 0, 'report');
10
11 INSERT INTO C
12 (scontent, nsource, suser, platform, stitle)
13 VALUES
14 (:new.nreport, :new.nid, :new.screateUser, 'PC-Chrome', '报告话题');
15 END tri_aft_ins_a;
16 /
Trigger created
SQL> INSERT INTO a VALUES(1,2,3,4);
1 row inserted
SQL> SELECT * FROM b;
SUSER SCONTENT CREATETIME NISPUBLIC SMODULEID
-------------------- -------------------- -------------------- -------------------- --------------------
1 2 3 0 report
SQL> SELECt * FROM c;
SCONTENT NSOURCE SUSER PLATFORM STITLE
-------------------- -------------------- -------------------- -------------------- --------------------
4 2 1 PC-Chrome 报告话题
SQL> INSERT INTO a VALUES(5,6,7,8);
1 row inserted
SQL> SELECt * FROM b;
SUSER SCONTENT CREATETIME NISPUBLIC SMODULEID
-------------------- -------------------- -------------------- -------------------- --------------------
1 2 3 0 report
5 6 7 0 report
SQL> SELECt * FROM c;
SCONTENT NSOURCE SUSER PLATFORM STITLE
-------------------- -------------------- -------------------- -------------------- --------------------
4 2 1 PC-Chrome 报告话题
8 6 5 PC-Chrome 报告话题
SQL>
全部回答
- 1楼网友:蓝房子
- 2021-02-05 14:11
CREATE trigger insert_emp_info ON A
AFTER INSERT
AS
BEGIN
select * from A
--话题资源表
INSERT INTO B (suser,scontent,createTime, nispublic, smoduleId)
VALUES ('A表中的screateUser','A表中的nid','A表中的screatetime',0,'report')
--话题信息表
INSERT INTO C (scontent, nsource, suser, platform, stitle)
VALUES ('A表中的nreport', 'B的nid', 'A表中的screateUser','PC-Chrome', '报告话题' ) ,
END
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯