on 04-10-2017 3:01 PM
Hi All,
I am inserting records from one table to another table by using cursor in procedure. If any error occurs in that time, handling errors by using exit handler.
But the issue is, when i am using cursor to load the data of (17 lacks) the cursor is taking 20 mins time.
Can you please give me an advise, if any other way is there to inserting records or for increasing the performance.
Thanks
Rajeswari A.
Thank you for reply...
Here while inserting if errors will occur i have to insert these errors into error table along with primary key of main table, what i am thinking this one is only possible with cursor.
Please see the below attached procedure.
CREATE PROCEDURE schemaname.procedure_name()
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
/*****************************************************************************************
VARIABLE DECLARATION
******************************************************************************************/
DECLARE errcode INT;
DECLARE errmsg NVARCHAR(5000);
DECLARE l_validation_flag NVARCHAR(5);
DECLARE l_ndb_insrt_ts1 NVARCHAR(20);
DECLARE l_ndb_insrt_ts2 NVARCHAR(20);
DECLARE l_message NVARCHAR(5000);
DECLARE l_count INT;
DECLARE l_job_name NVARCHAR(1000) := 'proc_name';
/*****************************************************************************************
creating cursor
*****************************************************************************************/
DECLARE CURSOR C1 FOR SELECT * FROM table1;
FOR CUR_ROW AS C1 DO
/*****************************************************************************************
ERROR HANDLING
******************************************************************************************/
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN l_validation_flag := 'N';
errcode = ::SQL_ERROR_CODE;
errmsg = ::SQL_ERROR_MESSAGE ;
CALL erorr_procedure(:errcode, :errmsg, CUR_ROW.seq_id, CUR_ROW.cycl_id, l_job_name);
END;
/*****************************************************************************************
INSERTING RECORDS TO TABLE2
******************************************************************************************/
l_validation_flag := 'Y';
SELECT TO_NVARCHAR (CURRENT_DATE,'YYYYMMDD HHMMSS') INTO l_ndb_insrt_ts2 FROM dummy ;
INSERT INTO table1 VALUES (select * from table2);
/*****************************************************************************************
ROLLBACK AND UPDATING TABLES
******************************************************************************************/
IF l_validation_flag = 'N' THEN ROLLBACK;
ELSEIF l_validation_flag = 'Y' THEN
SELECT TO_NVARCHAR (CURRENT_DATE,'YYYYMMDD HHMMSS') INTO l_ndb_insrt_ts1 FROM dummy;
UPDATE table1 ;
END IF;
END IF;
END;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I dont think there is any other way you can do this, since you are handling exceptions at individual statement level execution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is the need to loop through records while you insert them to the target table?
If this is a simple source to target insert, you can use INSERT INTO <target> SELECT <fields> from SOURCE WHERE <filter condition>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.