码迷,mamicode.com
首页 > 数据库 > 详细

oracle——存储过程

时间:2015-10-23 18:05:32      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

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
(
    CS_ZB IN INT :=20,
    pageNumber IN INT,
    pageSize IN INT,
    SUM1 out INT ,
    p_ReCursor0 out T_CURSOR
) IS
BEGIN
    if pageNumber is not null and pageSize is not null
    then
          select   COUNT(1) into  SUM1 from
        (
            select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE CS_ZB>10  union all
            select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE CS_ZB>10 UNION ALL
            select ,,,-120 今年销售额,-120 去年销售额  from dual WHERE CS_ZB>10
            union all
            select ,,,null 今年销售额,null 去年销售额  from dual  WHERE CS_ZB>10
            union all
            select ,,,0 今年销售额,0 去年销售额  from dual WHERE CS_ZB>10
        )aaa;
      open p_ReCursor0 for select  省,市,县,今年销售额,去年销售额 from
        (
            select rownum rownumber,A.* from
            (
                select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE CS_ZB>10  union all
                select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE CS_ZB>10 UNION ALL
                select ,,,-120 今年销售额,-120 去年销售额  from dual WHERE CS_ZB>10 
                union all
                select ,,,null 今年销售额,null 去年销售额  from dual WHERE CS_ZB>10
                union all
                select ,,,0 今年销售额,0 去年销售额  from dual WHERE CS_ZB>10
            )A
        )B
        WHERE rownumber  between  (pageNumber-1) *pageSize+1  AND  pageNumber*pageSize;
    else
      open p_ReCursor0 for    select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE CS_ZB>10  union all
        select YJ 省,EJ 市,SJ 县,SZ1 今年销售额,SZ2 去年销售额 FROM SZQCSBJ WHERE CS_ZB>10 UNION ALL
        select ,,,-120 今年销售额,-120 去年销售额  from dual WHERE CS_ZB>10
        union all
        select ,,,null 今年销售额,null 去年销售额  from dual WHERE CS_ZB>10
        union all
        select ,,,0 今年销售额,0 去年销售额  from dual WHERE CS_ZB>10;
    end if;
END PROC_PAGE;
END BAWQ_PROC_PAGE;

 

oracle——存储过程

标签:

原文地址:http://www.cnblogs.com/SunBlog/p/4904817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!