ITPub博客

首页 > 数据库 > Oracle > fetch v_cur 案例

fetch v_cur 案例

原创 Oracle 作者:hurp_oracle 时间:2014-11-27 14:29:49 0 删除 编辑
create or replace procedure count as
  v_sql varchar2(2000);
  cursor name_list is
    select table_name
      from user_tables;
  v_cur sys_refcursor;
  v_tname varchar2(30);
  v_total number;
begin
  for v_name in name_list loop
    v_sql := 'select ''' || v_name.table_name ||''' as tname, count(1) as total from '|| v_name.table_name;
    open v_cur for v_sql;
    loop
      fetch v_cur into v_tname, v_total;
      EXIT WHEN v_cur%NOTFOUND;
      dbms_output.put_line('v_tname = '||rpad(v_tname, 34, ' ')||', v_total = '||v_total);
    end loop;
    close v_cur;
  end loop;
end;
/

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29446986/viewspace-1348693/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-01-17

  • 博文量
    152
  • 访问量
    647370