Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

After insert trigger not updating all rows in a batch

OraCOct 20 2020 — edited Oct 20 2020

I've got 2 tables:
create table CUSTOMERS
(CUSTOMER_ID NUMBER(20,0),
SP_ID NUMBER(20,0),
UPDATED_ON TIMESTAMP);

create table CUST_DATA
(CUST_DATA_ID NUMBER(20,0),
CUSTOMER_ID NUMBER(20,0),
SP_ID NUMBER(20,0),
UPDATED_ON TIMESTAMP);

I've got a trigger on insert into the CUST_DATA table as follows that updates 2 columns (SP_ID and UPDATED_ON) from the CUSTOMERS table:
create or replace trigger CUST_DATA_AI
for insert on CUST_DATA
compound trigger
cust_id number(20,0);
after each row is
begin
cust_id := :new.CUSTOMER_ID;
end after each row;
after statement is
begin
update CUST_DATA set (CU.SP_ID, CU.CREATED_ON) = (select CI.SP_ID, CI.CREATED_ON from CUSTOMERS CI where CI.CUSTOMER_ID=cust_id) where CU.CUSTOMER_ID=cust_id;
end after statement;
end;
/

I have a java based application that is completing a number of inserts into the CUST_DATA table in a batch and then is submitted to the database all together. I'm seeing that the trigger seems to be only firing for the last inserted entry. Any ideas?

Comments
Post Details
Added on Oct 20 2020
1 comment
904 views