oracle,触发器或者存储过程实现,表A插入一条记录,表B和表C自动插入一条记录,详情如下
select*fromA--话题资源表INSERTINTOB(suser,scontent,createTime,nispublic,smoduleId)VALUES('...
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', '报告话题' ) ,
求大神指导! 展开
--话题资源表
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', '报告话题' ) ,
求大神指导! 展开
2个回答
展开全部
代码如下:
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 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
追问
你好,首先感谢你的回答,我有点疑问。
1、触发器放在表A上?
2、三张表的id都是自增的,在B表中插入表A的新增的id这样处理这样行么?
追答
触发器放在A表。可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询