Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Populate table from cursor Jump to:  
Category: >> Oracle PL/SQL >> Populate table from cursor Bookmark and Share

<< lastnext >>

Snippet Name: Populate table from cursor

Description: How to populate a PL/SQL Table from a cursor.

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 03rd, 2009

SET serveroutput ON
 
DECLARE
  -- Declare the PL/SQL table
  TYPE deptarr IS TABLE OF dept%ROWTYPE
       INDEX BY BINARY_INTEGER;
  d_arr deptarr;
 
  -- Declare cursor
  TYPE d_cur IS REF CURSOR RETURN dept%ROWTYPE;
  c1 d_cur;
 
  i NUMBER := 1;
BEGIN
  -- Populate the PL/SQL table from the cursor
  OPEN c1 FOR SELECT * FROM dept;
  LOOP
    EXIT WHEN c1%NOTFOUND;
    FETCH c1 INTO d_arr(i);
    i := i+1;
  END LOOP;
  CLOSE c1;
 
  -- Display the entire PL/SQL table on screen
  FOR i IN 1..d_arr.LAST LOOP
    DBMS_OUTPUT.put_line('DEPTNO : '||d_arr(i).deptno );
    DBMS_OUTPUT.put_line('DNAME  : '||d_arr(i).dname  );
    DBMS_OUTPUT.put_line('LOC    : '||d_arr(i).loc    );
    DBMS_OUTPUT.put_line('---------------------------');
  END LOOP;
END;
/
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 54 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?