简体   繁体   English

在一个表中插入后,在Oracle APEX中插入另一个表

[英]After insert in one table, insert into another table in Oracle APEX

What I would like to do is; 我想做的是 after I insert some data into table1, I would like some of that data automatically inserted into table2, such as the primary key from table1 inserted into table2 as a foreign key. 在将一些数据插入到table1中之后,我希望其中一些数据自动插入到table2中,例如将table1中的主键作为外键插入到table2中。

Is this done using a trigger. 使用触发器完成此操作吗? Not sure where to start looking first. 不知道从哪里开始寻找。

Cheers Brian 干杯布莱恩

Yes you can do that through trigger. 是的,您可以通过触发器来做到这一点。 You can do it like this: 您可以这样做:

  CREATE OR REPLACE TRIGGER my_trigger 
  before INSERT ON table1 
  REFERENCING NEW AS NEW 
  for each row
  BEGIN
    insert into table2(fk_column,column1) values(:new.pk_column_of_table1,'value1');
  END;

you can create a trigger as @vance said and you can use returning into clause if you are populating some of the columns dynamically 您可以按照@vance的说明创建触发器,如果​​动态填充某些列,则可以使用returning子句

INSERT INTO t1 VALUES (t1_seq.nextval, 'FOUR')
  RETURNING id INTO l_id;

have a look here 在这里看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM