I want to insert atleast 500,000 fresh records in one shot. For which I have used while loop inside procedure. My query is working fine but it is taking alot of time to execute. So, I am looking for a solution using which I can make the process of insertion of large volume of data faster. I have gone through many links but I didn't find them resourceful.
Note:
- I want to insert fresh data, not the data from existing table.
- Syntactically the code provided below is correct and working. So please do not provide any suggestions regarding syntax.
Below is my procedure:
BEGIN
DECLARE x INT;
DECLARE start_s INT;
DECLARE end_s INT;
SET x = 0;
PREPARE stmt FROM
'insert into primary_packing(job_id, barcode, start_sn, end_sn, bundle_number, client_code, deno, number_sheets, number_pins, status)
values (?,?,?,?,?,?,?,?,?,?)';
SET @job_id = job_id, @barcode = barcode, @bundle_number = bundle_number, @client_code = client_code, @deno = deno, @number_sheets = number_sheets, @number_pins = number_pins, @status = 1;
set @start_sn = start_sn;
set @end_sn = end_sn;
WHILE x <= multiply DO
set @start_s = (start_sn+(diff*x));
set @end_s = ((end_sn-1)+(diff*x)+diff);
EXECUTE stmt USING @job_id, @barcode, @start_s, @end_s, @bundle_number, @client_code, @deno, @number_sheets, @number_pins ,@status;
SET x = x + 1;
END WHILE;
DEALLOCATE PREPARE stmt;
END