1. create or replace procedure PCREPORT is
  2.  
  3. startDate DATE; --起始如期
  4. nowTime DATE; --当前日期
  5. nowTime2 DATE; --当前日期下限用于支持跨年
  6. orderDate DATE; --计算时候的当前下订单日期
  7. orderDate2 DATE; --跨年使用的日期范围下限
  8.  
  9. returns number; --退订总数
  10. renew number; --续费总数
  11. active number; --激活人数
  12. noActive number; --未激活人数
  13. activeReturn number; --激活退订人数
  14. noActiveReturn number; --未激活退订人数
  15. reportDateActive number; --报表时间激活的人数
  16.  
  17. tempStr varchar2(3000);
  18. i number;
  19. number_value number;
  20.  
  21. --1.起始时间与当前时间减法,用结果做循环遍历的次数
  22. --2.每次遍历在起始时间上加,遍历次数的月值
  23. --3.将这个时间值作为条件,查询统计出一个统计值,将这个值插入到数据库对应的字段
  24.  
  25. begin
  26. startDate := to_date('2009-04-01', 'yyyy-mm-dd');
  27.  
  28. /* SELECT to_char(sysdate, 'yyyy-mm-dd ') into tempStr from dual;
  29. nowTime := to_date(tempStr, 'yyyy-mm-dd');*/
  30.  
  31. select to_date(to_char(sysdate, 'YYYYMM') || '', 'YYYY-MM-DD')
  32. into nowTime
  33. from dual;
  34.  
  35. nowTime2 := add_months(nowTime, 1);
  36.  
  37. number_value := months_between(nowTime, startDate); --月份差
  38.  
  39. i := 0;
  40. for i in 0 .. number_value loop
  41.  
  42. orderDate := add_months(startDate, i);
  43. orderDate2 := add_months(orderDate, 1);
  44.  
  45. -- 续费及激活总数的计算
  46. select count(*)
  47. into renew
  48. from ord_order
  49. where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) =
  50. and (end_time = to_date('1900-01-01', 'yyyy-mm-dd') or
  51. end_time >= nowTime); --(select to_char(end_time, 'mm') from dual) >= '07');
  52.  
  53. --续费用户退订总人数
  54. select count(*)
  55. into returns
  56. from ord_order
  57. where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) = '05'
  58. and end_time between nowTime and nowTime2; --(select to_char(end_time, 'mm') from dual) = '07';
  59.  
  60. --续费用户激活未退订
  61. select count(*)
  62. into noActiveReturn
  63. from ord_order
  64. where AGREE_TO_TIME between orderDate and orderDate2 -- (select to_char(AGREE_TO_TIME, 'mm') from dual) = '06'
  65. and end_time between nowTime and nowTime2 --(select to_char(end_time, 'mm') from dual) = '07'
  66. and BECOME_EFFECTIVE_TIME < nowTime --to_date('2009-07-01', 'yyyy-mm-dd')
  67. and BECOME_EFFECTIVE_TIME = to_date('1900-01-01', 'yyyy-mm-dd');
  68.  
  69. -- 当前报表月在个月激活的人数
  70. select count(*)
  71. into reportDateActive
  72. from ord_order
  73. where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) = '05'
  74. and (end_time = to_date('1900-01-01', 'yyyy-mm-dd') or
  75. end_time >= nowTime) --(select to_char(end_time, 'mm') from dual) >= '06')
  76. and BECOME_EFFECTIVE_TIME between nowTime and nowTime2; --(select to_char(BECOME_EFFECTIVE_TIME, 'mm') from dual) = '06';
  77.  
  78. -----------------------------之前经过校验得到正确结果---------------------
  79. --续费用户报表月激活人数
  80. select count(*)
  81. into active
  82. from ord_order
  83. where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) = '04'
  84. and BECOME_EFFECTIVE_TIME != to_date('1900-01-01', 'yyyy-mm-dd')
  85. and BECOME_EFFECTIVE_TIME < nowTime --(select to_char(BECOME_EFFECTIVE_TIME, 'mm') from dual) < '07'
  86. and ((end_time = to_date('1900-01-01', 'yyyy-mm-dd')) or
  87. end_time >= nowTime); --(select to_char(end_time, 'mm') from dual) >= '07');
  88.  
  89. activeReturn := returns - noActiveReturn;
  90.  
  91. noActive := renew - active - reportDateActive;
  92.  
  93. --做插入操作
  94. insert into report_pc51
  95. (REPORTDATE,
  96. ORDERDATE,
  97. RENEW,
  98. RETURNS,
  99. NOACTIVERETURN,
  100. REPORTDATEACTIVE,
  101. ACTIVERETURN,
  102. ACTIVE,
  103. NOACTIVE)
  104. values
  105. (nowTime,
  106. orderDate,
  107. renew,
  108. returns,
  109. noActiveReturn,
  110. reportDateActive,
  111. activeReturn,
  112. active,
  113. noActive);
  114.  
  115. dbms_output.put_line(i);
  116. end loop;
  117.  
  118. COMMIT;
  119.  
  120. end PCREPORT;

Oracle 存储过程实例的更多相关文章

  1. oracle存储过程实例

    oracle存储过程实例 分类: 数据(仓)库及处理 2010-05-03 17:15 1055人阅读 评论(2)收藏 举报 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的P ...

  2. Oracle 存储过程实例2

    --创建存储过程 CREATE OR REPLACE PROCEDURE xxxxxxxxxxx_p ( --参数IN表示输入参数,OUT表示输入参数,类型可以使用任意Oracle中的合法类型. is ...

  3. ORACLE 存储过程实例 [备忘录]

    统计报表:用户登录量(平台点击量)每月月初定时任务统计前一个月的登陆次数.登陆账号数.账号总数. 使用存储过程把查询的值存储到表 RP_MONTH_CLICK 中. create or replace ...

  4. Oracle存储过程实例分析总结(代码)

    1.存储过程结构 1.1 第一个存储过程 ? 1 2 3 4 5 6 7 8 9 10 11 12 CREATE OR REPLACE PROCEDURE proc1 (     para1 varc ...

  5. JAVA调用oracle存储过程实例

    1.创建添加存储过程 CREATEORREPLACEPROCEDURE stu_proc(v_id INNUMBER, v_name INVARCHAR2, v_age INNUMBER) AS BE ...

  6. oracle存储过程的例子

    oracle存储过程的例子 分类: 数据(仓)库及处理 2010-05-03 17:15 1055人阅读 评论(2)收藏 举报 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的 ...

  7. oracle中print_table存储过程实例介绍

    oracle中pro_print_table存储过程实例介绍 存储过程(Stored Procedure),就是一组用于完成特定数据库功能的SQL语句集,该SQL语句集经过编译后存储在数据库系统中.这 ...

  8. Oracle创建表语句(Create table)语法详解及示例、、 C# 调用Oracle 存储过程返回数据集 实例

    Oracle创建表语句(Create table)语法详解及示例 2010-06-28 13:59:13|  分类: Oracle PL/SQL|字号 订阅 创建表(Create table)语法详解 ...

  9. oracle 存储过程

    来自:http://www.jb51.net/article/31805.htm Oracle存储过程基本语法 存储过程 1 CREATE OR REPLACE PROCEDURE 存储过程名 2 I ...

随机推荐

  1. Quartz.Net使用

    相关的Quartz的Demo https://yunpan.cn/cY3GZGcyTSQxu  访问密码 8b60 官方的写的也挺仔细的.http://www.quartz-scheduler.net ...

  2. What Makes a Good Programmer Good?

    I’ve worked with a lot of programmers over the years — some of them super amazing, and some distinct ...

  3. Memcached 使用

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  4. 在Linux下进行磁盘分区

      1.         分区前的规划   2.         查看本机上的磁盘信息   3.         对第二个磁盘进行交换式分区操作(输入m为帮助信息) 图 1:n为新建分区 图 2:p为 ...

  5. Iframe跨域_ASP.NET

    1.描述: A系统 需要 调用 B系统的页面,被调用的B系统的页面b.html内部嵌套了iframe框架c.aspx地址页 2.问题呈现: ie浏览器下 Chrome浏览器下 追踪 3.问题原因: X ...

  6. Swift学习链接

    http://wiki.jikexueyuan.com/project/swift/chapter1/02_a_swift_tour.html

  7. 实例介绍Cocos2d-x精灵菜单和图片菜单

    精灵菜单类是MenuItemSprite,图片菜单类是MenuItemImage.由于MenuItemImage继承于MenuItemSprite,所以图片菜单也属于精灵菜单.为什么叫精灵菜单呢?那是 ...

  8. JavaScript之字符串

    一.声明方式 1. 直接赋值 var str = 'hello javascript'; 2. 构造函数 var str2 = new String('hello world'); 这两种有什么区别呢 ...

  9. AngularJS中的MVC模式

    MVC根据逻辑关系,把前端项目的代码分为三个层次 model:模型,就是业务数据,前端项目中就是JS变量. view:视图,就是业务数据在用户面前的展现,前端项目中就是HTML. controller ...

  10. 13.mariadb-rhce考试解题思路

    1.安装mariadb ①yum install -y mariadb mariadb-server 或者 yum groupinstall -y mariadb 2.备份和还原数据库 ①备份:mys ...