I have the following PL/SQL block that creates a procedure to insert a new cat:
CREATE OR REPLACE PROCEDURE INSERT_NEW_CAT(AGE NUMBER, WEIGHT NUMBER, NAME VARCHAR2)
AS
BEGIN
INSERT INTO CATS(cat_id,age,weight,name)
VALUES(cat_id_sequence.nextval,age,weight,name);
END INSERT_NEW_CAT;
And the following Java block to batch insert these cats:
CallableStatement statement = conn.prepareCall("{CALL insert_new_cat(?,?,?)}");
for(int i = 0; i < 50000;i++)
{
statement.setInt(1, i);
statement.setInt(2,i);
statement.setString(3,"Test");
statement.addBatch();
if(i % 16382== 0) //max value my batch can support on my hardware
{
statement.executeBatch();
}
}
statement.executeBatch();
So the issue with this is I can only persist 700 records a second, which is quite slow. I believe the issue is that I invoke the above PL/SQL function once per row (or once per batch entry). How can I re-write the above function to take an array of these statements and do a bulk insert to reduce the number of calls to the function to N modulo 16382 + 1? The database is Oracle 10g.