Home » SQL & PL/SQL » SQL & PL/SQL » how to read from the collection ..
how to read from the collection .. [message #37467] Sun, 10 February 2002 23:50 Go to next message
ksr
Messages: 112
Registered: January 2002
Senior Member
Hi,
i want something like this.

i want to create a type like table (table is already existing).

like

type cur1 is ref cursor;
type cur2 is table of emp%rowtype;
c1 cur1;
c2 cur2;

begin

open c1 for select * from emp;
fetch c1 bulk collect into c2;
close c1;

forall i in c2.first..c2.last

here my doubt.....how to read values from type c2..

insert into t1 values(sequence1.nextval,c2(i)) returning id

------how to read values above

Any help is appreciated
Re: how to read from the collection .. [message #37477 is a reply to message #37467] Mon, 11 February 2002 08:19 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
does this help?
http://asktom.oracle.com/pls/ask/f?p=4950:8:97868::NO::F4950_P8_DISPLAYID,F4950_P8_B:246014735810,Y
Re: how to read from the collection .. [message #37532 is a reply to message #37467] Wed, 13 February 2002 07:22 Go to previous messageGo to next message
ksr
Messages: 112
Registered: January 2002
Senior Member
The link given by you do not satisfy my requirements..
i want something like...how to create a type of table and how to assign values to it and how to read them.

any help is appreciated
Re: how to read from the collection .. [message #37534 is a reply to message #37467] Wed, 13 February 2002 07:30 Go to previous messageGo to next message
ksr
Messages: 112
Registered: January 2002
Senior Member
Hi,
the link does not provide me with sufficient information.

What i exactly want is creating a tyope of table,
how to assign values to it and how to retrieve the values
Re: how to read from the collection .. [message #37537 is a reply to message #37534] Wed, 13 February 2002 07:47 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
This uses a pl/sql table which is virtually the same.
-- For sqlplus:
set serveroutput on size 10000
DECLARE
TYPE cat_pltab_type IS TABLE OF cat%ROWTYPE INDEX BY BINARY_INTEGER;
cat_pltab cat_pltab_type;

CURSOR c1 IS SELECT * FROM cat;

i NUMBER;
BEGIN
OPEN c1;

LOOP
FETCH c1 INTO cat_pltab (cat_pltab.COUNT + 1);
EXIT WHEN c1%NOTFOUND;
END LOOP;

FOR i IN 1 .. cat_pltab.COUNT
LOOP
DBMS_OUTPUT.put_line (cat_pltab (i).table_type || ', ' || cat_pltab (i).table_name);
END LOOP;
END;
/
Previous Topic: SYSDATE of remote database
Next Topic: batch processing
Goto Forum:
  


Current Time: Fri Apr 26 00:30:02 CDT 2024