Reputation: 859
I have a stored procedure in which I am inserting data in Table T1
. Then based on the inserted data in Table T1
, I have to insert data in Table T2
(see below code). My question is - Do I need to use the commit;
twice (after inserting data in Table T1
and then again after inserting in Table T2
) or can I just use it once in the end and I will be join on the data inserted in Table T1
within that session of procedure while inserting data in Table T2
?
CREATE OR REPLACE PROCEDURE FOO
AS
BEGIN
INSERT INTO T1 (ID, NAME, PHONE)
SELECT ID,
NAME,
PHONE
FROM CUST;
COMMIT; --Do I really need to use this commit here?
INSERT INTO T2 (ID,NAME,CITY)
SELECT C.ID,
C.NAME,
C.CITY
FROM CUST C
JOIN T1 X
ON X.ID = C.ID
COMMIT;
END FOO;
Upvotes: 1
Views: 1219
Reputation: 384
No. You don't have to put that first commit. The second commit does the job.
Upvotes: 2