Search code examples
sqlplsqlsql-navigator

Optimizing script for faster insert of 10,000 records in SQL Navigator?


I'm attempting to insert 10,000 records into a table using INSERT statements in SQL Navigator. The process is taking longer than expected. Does anyone have suggestions on how to expedite this operation?

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Alex', 'Alex Perera', 'Abcd 300', 'Stavanger', '4006', 'Norway');

...
...
... 10,000 records
...
...

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Bimesh', 'Bimesh Perera', '97 Elgern', 'London', '2008', 'UK');

Solution

  • Wrap every thousand inserts (or so) in a PL/SQL anonymous block:

    BEGIN
       INSERT INTO ...
    
       ...
       ... 1,000 records
       ...
    END;
    /
    
    BEGIN
       INSERT INTO ...
    
       ...
       ... The next 1,000 records
       ...
    END;
    /