I’m new to PL/SQL and I’m working on writing a bulk insert. I have a nested cursor and inside the inner cursor I want to add records to a collection that I will then perform the bulk insert with. I create the collection as:
TYPE mydata_tab IS TABLE OF mydata%ROWTYPE INDEX BY BINARY_INTEGER;
v_mydata_tab mydata_tab;
And then my cursors look like:
FOR rec_one IN cursor_one LOOP
strKey := rec_one.key;
FOR rec_two IN cursor_two LOOP
-- here is where I want to add a record to v_mydata_tab, that uses properties of both rec_one and rec_two
-- something like SELECT rec_one.key, rec_one.a, rec_two.b INTO v_mydata_tab;
END LOOP;
END LOOP;
I’ve played around with SELECT INTO and INSERT INTO, but can’t seem to figure out how to get this to work.
You can do it like this:
Of course, if you can combine the SQL of the 2 cursors into one select statement, you could do this instead:
Or if too much data: