Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help passing table name as parameter to a procedure

vishm8Jul 27 2011 — edited Aug 1 2011
Hello,

i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
CREATE OR REPLACE
PROCEDURE excur(
    p_tbl user_tables.table_name%type )
AS
  type rc is ref cursor;
  c rc;
  res BOOLEAN;
BEGIN
  open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
  close c;
END excur;
When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2011
Added on Jul 27 2011
12 comments
5,066 views