Sqlplus中调试带cursor的存储过程

  1. 存储过程
    1. create or replace package pkg_test as
        type t_cursor is ref cursor;
        procedure sp_getInfoCatalog(p_userId      in varchar2,
                                    p_privilege   in number,
                                    p_rowsPerPage in number,
                                    p_curPage     in number,
                                    p_rowCount    out number,
                                    cur_catalogs  out t_cursor);
      end;
      /
    2. create or replace package body pkg_test as
        procedure sp_getInfoCatalog(p_userId      in varchar2,
                                    p_privilege   in number,
                                    p_rowsPerPage in number,
                                    p_curPage     in number,
                                    p_rowCount    out number,
                                    cur_catalogs  out t_cursor) is
          v_sqlstr      varchar2(1024);
          v_sqlstrpage  varchar2(1024);
          v_rowsPerPage number(18);
          v_curPage     number(18);
          v_pageCount   number(18);
          v_pageMod     number(1);
          v_rowBegin    number(18);
          v_rowEnd      number(18);
        begin
          v_sqlstr := 'SELECT COUNT(1) FROM TUSER';
          execute immediate v_sqlstr into p_rowCount;
       
          v_sqlstr      := 'SELECT USERID,NAME,LOGINID FROM TUSER';
          v_rowsPerPage := p_rowsPerPage;
          if nvl(v_rowsPerPage, 0) < 1 then
            v_rowsPerPage := 10;
          end if;
          if p_rowCount > v_rowsPerPage then
            v_pageMod   := p_rowCount mod v_rowsPerPage;
            v_pageCount := p_rowCount / v_rowsPerPage;
            if v_pageMod > 0 then
              v_pageCount := v_pageCount + 1;
            end if;
            v_curPage := p_curPage;
            if v_curPage < 1 then
              v_curPage := 1;
            end if;
            if v_curPage > v_pageCount then
              v_curPage := v_pageCount;
            end if;
            v_rowBegin := (v_curPage - 1) * v_rowsPerPage + 1;
            v_rowEnd   := v_rowBegin + v_rowsPerPage;
            v_sqlstrpage   := 'SELECT USERID,NAME,LOGINID FROM (SELECT ORIGINTABLE.*, ROWNUM RM FROM (' ||
                          v_sqlstr ||
                          ') ORIGINTABLE WHERE ROWNUM<:W_ROWEND) WHERE RM>=:W_ROWBEGIN';
            open cur_catalogs for v_sqlstrpage
              using v_rowEnd, v_rowBegin;
          else
            open cur_catalogs for v_sqlstr;
          end if;
        end sp_getInfoCatalog;
      end pkg_test;
      /
  2. Sqlplus调试代码
    1. declare
        v_userId      tuser.userid%type;
        v_userName    tuser.name%type;
        v_userLoginId tuser.loginid%type;
        v_rowsPerPage number(4) not null := 2;
        v_curPage     number(18) not null := 4;
        v_rowsCount   number(18);
        cur_info      pkg_test.t_cursor;
      begin
        v_userId := '-9999';
        pkg_test.sp_getInfoCatalog(v_userid,
                                      0,
                                      v_rowsPerPage,
                                      v_curPage,
                                      v_rowsCount,
                                      cur_info);
        dbms_output.put_line('rowsCount = ' || v_rowsCount);
        loop
          fetch cur_info
            into v_userId, v_userName, v_userLoginId;
          exit when cur_info%NOTFOUND;
          dbms_output.put_line('userid=' || v_userId || ' name=' ||
                               v_userName);
        end loop;
        close cur_info;
      end;
      /
  3. 总结
    1. pl/sql developer 里的Command Window里面输入(Sqlplus调试代码)调试存储过程会出现“refcursor don't supported!“的错误,换到sqlplus里面调试一切正常。
  4. 参考文档
    1. SQL*Plus User's Guide and Reference Release 9.2

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值