Home » SQL & PL/SQL » SQL & PL/SQL » urgent..how to assign a table name dynamically in a cursor
urgent..how to assign a table name dynamically in a cursor [message #38586] Mon, 29 April 2002 08:01 Go to next message
ksr
Messages: 112
Registered: January 2002
Senior Member
Hi,

I want to assign the table name dynamically to a cursor.

Like i have

create or replace procedure test(tabname in varchar2) as
cursor c1 is select * from :tabname; --here i want to replace the tablename with the parameter received to the procedure..how do i do this..
Re: urgent..how to assign a table name dynamically in a cursor [message #38589 is a reply to message #38586] Mon, 29 April 2002 09:23 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
You won't be able to use a declared cursor, but here is an example using a weak ref cursor:

create or replace procedure test (tabname in all_tables.table_name%type)
is
  type rc is ref cursor;
  v_rc  rc;
begin
  open v_rc for 'select * from ' || tabname;
  fetch v_rc into ...;
  close v_rc;
end;
Previous Topic: Urgent Urgent ....
Next Topic: Re: How to use '&' as place holder in select statement in procedure
Goto Forum:
  


Current Time: Thu Apr 18 15:14:24 CDT 2024