DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: table name as parameter to a fucntion

  1. #1
    Join Date
    Jun 2001
    Posts
    316
    Sorry ..but this is a plsql question...

    Can I pass table name as a parameter to a function .
    if yes..Can any1 pl send me an example..
    thanx
    Sam

  2. #2
    Join Date
    Jun 2001
    Location
    NJ
    Posts
    118
    Sam,
    Try this. I posted the same in the other thread. But, to make it faster. I am re-posting it here.
    procedure rows_selected_cur
    is
    table_name1 VARCHAR2(50) :='Pal_states';
    st_id1 varchar2(2) := 'AK' ;
    sql_stmt varchar2(80) :='';
    where_condition varchar2(80) :='';
    emp_rec pal_states%rowtype;
    TYPE EmpCurTyp IS REF CURSOR; -- define weak REF CURSOR type
    emp_cv EmpCurTyp; -- declare cursor variable

    BEGIN
    --test_id :='NJ';
    -- open cursor variable

    where_condition := ' WHERE ST_ID = ''' || st_id1 || '''' ;
    where_condition := '';
    sql_stmt := 'SELECT * FROM ' || table_name1 || where_condition;
    dbms_output.put_line(sql_stmt );
    OPEN emp_cv FOR sql_stmt; -- INTO emp_rec; --USING st_id1;
    loop
    fetch emp_cv into emp_rec;
    --dbms_output.put_line ('Sql_row_count ' || emp_cv%ROWCOUNT);
    exit when emp_cv%notfound;
    end loop;

    dbms_output.put_line ('Sql_row_count ' || emp_cv%ROWCOUNT);
    close emp_cv;
    --dbms_output.put_line (emp_rec.st_desc);
    end;

    Hope this helps.

    Gd_1976.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width