oracle——存储过程分页

1、包头:

CREATE OR REPLACE PACKAGE BAWQ_PROC_PAGE IS    -- BAWQ_PROC_PAGE  是包头名
    TYPE T_CURSOR IS REF CURSOR;    --动态游标
    PROCEDURE PROC_PAGE  --存储过程名字
    (
              CS_ZB IN INT :=20,
              pageNumber IN INT,
              pageSize IN INT,
              SUM1 out INT ,
              p_ReCursor0 out T_CURSOR
      );
END BAWQ_PROC_PAGE;

2、包体:

CREATE OR REPLACE PACKAGE BODY BAWQ_PROC_PAGE IS
PROCEDURE PROC_PAGE
(
    p_CS_ZB  INT ,
    p_pageNumber  INT,
    p_pageSize  INT,
    SUM1 out varchar,
    RE_CURSOR out T_CURSOR
) IS
BEGIN
    if p_pageNumber is not null and p_pageSize is not null
    then
          select   count(1) into  SUM1 from
        (
            select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE p_CS_ZB>10 union all
      select '1','2','3',4,5 from dual
        )aaa;
      open RE_CURSOR for select  省,市,县,今年销售额,去年销售额 from
        (
            select rownum rownumber,A.* from
            (
                select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE p_CS_ZB>10 union all
      select '1','2','3',4,5 from dual
            )A
        )B
        WHERE rownumber  between  (p_pageNumber-1) *p_pageSize+1  AND  p_pageNumber*p_pageSize;
    else
      open RE_CURSOR for    select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE p_CS_ZB>10 union all
      select '1','2','3',4,5 from dual;
    end if;
END PROC_PAGE;
END BAWQ_PROC_PAGE;

 

posted @ 2015-10-23 15:58  志在天涯  阅读(272)  评论(0编辑  收藏  举报