create or replace procedure getData(tabelName in varchar2,myCursor out sys_refcursor)
as
begin
  open myCursor for select * from tabelName;
exception
  when others then
    dbms_output.PUT_LINE(sqlcode||','||sqlerrm);
end getData;编译提示:表或视图不存在,tabelName换成emp就可以,但是如果我要取表名为传入参数的值,要怎么写才行

解决方案 »

  1.   

    create or replace procedure getData(tabelName tablename,myCursor out sys_refcursor)
    as
    begin
      open myCursor for select * from tabelName;
    exception
      when others then
        dbms_output.PUT_LINE(sqlcode ¦ ¦',' ¦ &brvbarsqlerrm);
    end getData; 
      

  2.   

    Try it ..
    create or replace procedure getData(tabelName in varchar2,myCursor out sys_refcursor) 
    as 
    str   varchar2(200); 
    begin
      str:='select * from '||tabelName ;
      open myCursor for str; 
    exception 
      when others then 
        dbms_output.PUT_LINE(sqlcode ¦ ¦',' ¦ ¦sqlerrm); 
    end getData;