Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ref cursor and bulk collect dynamic sql

Status
Not open for further replies.

zapster

Programmer
Jun 8, 2001
36
GB
Hi all

I'm using oracle 8i (8.1.6.1.0) and at the moment I cannot seem to get this dynamic sql to work with a bulk collect. ok the sql statement is currently hard coded but it will be made up on the fly, once I have got pass this problem. My objective is then to update a other tables using the collection I have generated.

Please [thumbsup2] can someone have a look at my code and tell me where I have gone wrong. [bigsmile]

Code:
DECLARE

TYPE cat_varray IS TABLE OF promo_groups_expanded.VALUE%TYPE;
TYPE pgi_varray IS TABLE OF promo_groups_expanded.PROMO_GROUP_ID%TYPE;


TYPE aTyp is REF CURSOR;

b_cur aTyp;

catalog_nos 	cat_varray;
promo_group_ids	pgi_varray;

sql_stmt varchar2(2000);


BEGIN

sql_stmt := 'select promo_group_id from promo_groups_expanded';											 


open b_cur FOR sql_stmt;
FETCH b_cur BULK COLLECT into promo_group_ids,catalog_nos;
CLOSE b_cur;


END;

I get the following error
ORA-01001: invalid cursor
ORA-06512: at line 23

Thanks

Zapster
 
Sorry,

I missed the other column when typing it up to post..



Code:
DECLARE

TYPE cat_varray IS TABLE OF promo_groups_expanded.VALUE%TYPE;
TYPE pgi_varray IS TABLE OF promo_groups_expanded.PROMO_GROUP_ID%TYPE;


TYPE aTyp is REF CURSOR;

b_cur aTyp;

catalog_nos     cat_varray;
promo_group_ids    pgi_varray;

sql_stmt varchar2(2000);


BEGIN

sql_stmt := 'select promo_group_id, value from promo_groups_expanded';                                             


open b_cur FOR sql_stmt;
FETCH b_cur BULK COLLECT into promo_group_ids,catalog_nos;
CLOSE b_cur;


END;
 
I'm sure that you need at least 8.1.7, because 8.1.6 had a lot of restrictions with weak cursors. In 8.1.6. you may define a number of parametrized cursors and then open ref cursor for one of them. In any case to use ref cursor with bulk clause your cursor should be describable.

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top