Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

bulk insert of values from a VARRAY?

TPD-OpitzJan 14 2011 — edited Jan 18 2011
Hello,

I have a table with an expensive check in its after insert statement trigger. Therefore I'd like to do inserts as bulk rather than individual inserts.

I've collected the values to insert in a varray but I don't know how to create a bulk insert statement with it.

This is my failing aproach:
CREATE OR REPLACE TYPE my_collection IS VARRAY (256) OF NUMBER;

CREATE TABLE test_bulk
(
  test_id    NUMBER
, id_test_1  NUMBER
, id_test_2  NUMBER
);

DECLARE
  my_collection_test  my_collection;
  v_count             NUMBER;
BEGIN
      SELECT LEVEL
        BULK COLLECT INTO my_collection_test
        FROM DUAL
  CONNECT BY LEVEL < 15;
  v_count  := my_collection_test.LAST;
  INSERT INTO test_bulk (id_test_1, id_test_2)
    SELECT 1, my_collection_test(rownum)
      FROM dual CONNECT BY LEVEL < v_count;
END;

DROP TABLE test_bulk;

DROP TYPE my_collection;
What I get is a ORA-06532: Subscript outside of limit, ORA-06512: at line 10

How do I do this correctly?

bye
TPD
This post has been answered by Centinul on Jan 14 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 15 2011
Added on Jan 14 2011
25 comments
5,993 views