存储过程中输入表名还有输出游标以及其测试块

来源:互联网 发布:靠谱网络兼职平台 编辑:程序博客网 时间:2024/05/23 00:05

--游标作为一个类型共用

create package pack1 is
type my_cursor is ref cursor;
end;

--输出游标为了程序后续使用,此游标打印所有输入表名的所有内容

create or replace procedure showall(v_table varchar2,v_out_result out pack1.my_cursor) is

begin
 open v_out_result for ' select * from '||v_table;

end showall;


--测试过程:


declare
v_table varchar2(20):='userTable';
v_out pack1.my_cursor;
tt usertable%rowtype;
begin
  showall(v_table,v_out_result =>v_out );
  loop
  fetch v_out into tt;
  dbms_output.put_line(tt.userid||tt.username);
  exit when v_out %notfound;
  end loop;
  close v_out;
  end;