I have to write a script with multiple insert. I did that too, and ran the script in Toad. The script completed in roughly 35 - 40 minutes.
I then applied that script to autosys, and ran it again (that's how it's supposed to be used). And this time, it kept on running for more than 1.5 hours.
I have to manually kill that active session in Oracle.
Please see my script and let me know, why it didn't completed in intended 40 min timeframe and kept on running for more than 1.5 hours.
EDIT: Would like to mention that common commands like 'commit' is called in a parent script which is called by Autosys. My script is one of the child script which is been called in the parent script.
-- Begining of Consolidated queries for Slow performing Talend Jobs
SET SERVEROUTPUT ON;
spool Consolidated.log;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
SET DEFINE OFF;
ALTER SESSION SET GLOBAL_NAMES=FALSE;
DECLARE
ExtractType NUMBER(9);
RecordsExtracted NUMBER(9);
CurStatus NUMBER(9);
StartDate date;
ErrorMessage NVARCHAR2(1000);
LastExtrctTimestamp DATE;
-- TABLE1
BEGIN
StartDate := sysdate;
ExtractType := 44;
DELETE FROM Table1;
INSERT INTO Table1
SELECT Statement....;
RecordsExtracted := SQL%RowCount;
DBMS_OUTPUT.put_line('Table1 Records Extracted:' || RecordsExtracted);
-- On Success
CurStatus := 2;
ErrorMessage := 'Table1 Complete';
INSERT INTO ExtractRecords(ExtractType, RecordsExtracted, Status, ExtractTimestamp, StartDate, EndDate, ErrorMessage)
VALUES (ExtractType, RecordsExtracted, CurStatus, SysDate, StartDate, SysDate, ErrorMessage);
INSERT INTO LoadRecords (LoadType,Status,LoadTimestamp,StartDate,EndDate)
VALUES (ExtractType, CurStatus, SysDate, StartDate, SysDate);
-- TABLE2 RESULTS
StartDate := sysdate;
ExtractType := 78;
DELETE FROM Table2;
INSERT INTO Table2
SELECT Statement....;
RecordsExtracted := SQL%RowCount;
DBMS_OUTPUT.put_line('Table2 Records Extracted:' || RecordsExtracted);
-- On Success
CurStatus := 2;
ErrorMessage := 'Table2 Complete';
INSERT INTO ExtractRecords(ExtractType, RecordsExtracted, Status, ExtractTimestamp, StartDate, EndDate, ErrorMessage)
VALUES (ExtractType, RecordsExtracted, CurStatus, SysDate, StartDate, SysDate, ErrorMessage);
INSERT INTO LoadRecords (LoadType,Status,LoadTimestamp,StartDate,EndDate)
VALUES (ExtractType, CurStatus, SysDate, StartDate, SysDate);
-- TABLE3
StartDate := sysdate;
ExtractType := 81;
DELETE FROM Table3;
INSERT INTO Table3
SELECT Statement....;
RecordsExtracted := SQL%RowCount;
DBMS_OUTPUT.put_line('Table3 Records Extracted:' || RecordsExtracted);
-- On Success
CurStatus := 2;
ErrorMessage := 'Table3 Complete';
INSERT INTO ExtractRecords(ExtractType, RecordsExtracted, Status, ExtractTimestamp, StartDate, EndDate, ErrorMessage)
VALUES (ExtractType, RecordsExtracted, CurStatus, SysDate, StartDate, SysDate, ErrorMessage);
INSERT INTO LoadRecords (LoadType,Status,LoadTimestamp,StartDate,EndDate)
VALUES (ExtractType, CurStatus, SysDate, StartDate, SysDate);
-- TABLE4
StartDate := sysdate;
ExtractType := 57;
DELETE FROM Table4;
INSERT INTO Table4
SELECT Statement....;
RecordsExtracted := SQL%RowCount;
DBMS_OUTPUT.put_line('Table4 Records Extracted:' || RecordsExtracted);
-- On Success
CurStatus := 2;
ErrorMessage := 'Table4 Complete';
INSERT INTO ExtractRecords(ExtractType, RecordsExtracted, Status, ExtractTimestamp, StartDate, EndDate, ErrorMessage)
VALUES (ExtractType, RecordsExtracted, CurStatus, SysDate, StartDate, SysDate, ErrorMessage);
INSERT INTO LoadRecords (LoadType,Status,LoadTimestamp,StartDate,EndDate)
VALUES (ExtractType, CurStatus, SysDate, StartDate, SysDate);
END;
spool off;
exit;
/
INSERT INTO ... SELECT ...statements, but those could be inserting a couple of rows, or a couple of million rows. I would suggest stepping through each statement here, checking the execution plans as you go.TRUNCATEinstead ofDELETE, and/*+ PARALLEL APPEND*/hints may make this process run many times faster.