Wednesday, November 6, 2013

PL SQL: open ref cursor from explicit cursor

PROCEDURE my_proc(x_ref_cursor OUT sys_refcursor) IS

    TYPE my_array_type IS TABLE of MY_TABLE%ROWTYPE;
    my_array my_array_type;
BEGIN
    OPEN x_ref_cursor FOR SELECT * FROM MY_TABLE;

    FETCH x_ref_cursor BULK COLLECT INTO my_array;

    -- Do something with my_array...
    FORALL i IN 1 .. my_array.COUNT
        INSERT INTO MY_TABLE2 (
            col1,
            col2,
            col3)
        VALUES (
            my_array(i).col1,
            my_array(i).col2,
            my_array(i).col3
        );
END;