I’m rather new to Oracle PL/SQL, so I’m not sure whether it’s possible to do something like this:
Two tables – T1 and T2 – T1.id is foreign key referencing T2.id, each table has a sequence;
I’ve written a function that when it’s called allows the user to insert new rows in T1 – will call it func1, same for T2 – func2;
Also a function that get us the last inserted sequence in a table – getLastSeq(table);
So, now I’m trying to create a trigger after insert on T2 calls func1, allowing the user to write the input info.
CREATE OR REPLACE TRIGGER trig1
AFTER INSERT ON T2
DECLARE
-----?----
BEGIN
----?----
dbms_output.put_line(func1(:col1, :col2));
----?----?
END;
But all my possible attempts to do so die with errors about :col1 not being a bad bind var.
I’m not quite sure that I understand what you’re trying to accomplish.
T2) could ever logically insert a row into a child table (T1). That would imply thatT1is not really a child table which implies that you have some sort of problem with the data model.If your goal is to pass the newly inserted
COL1andCOL2tables from the row that was just inserted intoT2to thePROC1procedure, my guess is that you want something likeIt sounds, though, like you may not want to use a trigger at all. If you want to create an order, you’d normally have a procedure that executes multiple
INSERTstatements rather than trying to insert into the child table from a trigger on the parent. Something like this, for example, is going to be much clearer and much easier to maintain than a trigger-based solution.