create or replace procedure PCREPORT is

  startDate  DATE; --起始如期
nowTime DATE; --当前日期
nowTime2 DATE; --当前日期下限用于支持跨年
orderDate DATE; --计算时候的当前下订单日期
orderDate2 DATE; --跨年使用的日期范围下限 returns number; --退订总数
renew number; --续费总数
active number; --激活人数
noActive number; --未激活人数
activeReturn number; --激活退订人数
noActiveReturn number; --未激活退订人数
reportDateActive number; --报表时间激活的人数 tempStr varchar2(3000);
i number;
number_value number; --1.起始时间与当前时间减法,用结果做循环遍历的次数
--2.每次遍历在起始时间上加,遍历次数的月值
--3.将这个时间值作为条件,查询统计出一个统计值,将这个值插入到数据库对应的字段 begin
startDate := to_date('2009-04-01', 'yyyy-mm-dd'); /* SELECT to_char(sysdate, 'yyyy-mm-dd ') into tempStr from dual;
nowTime := to_date(tempStr, 'yyyy-mm-dd');*/ select to_date(to_char(sysdate, 'YYYYMM') || '', 'YYYY-MM-DD')
into nowTime
from dual; nowTime2 := add_months(nowTime, 1); number_value := months_between(nowTime, startDate); --月份差 i := 0;
for i in 0 .. number_value loop orderDate := add_months(startDate, i);
orderDate2 := add_months(orderDate, 1); -- 续费及激活总数的计算
select count(*)
into renew
from ord_order
where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) =
and (end_time = to_date('1900-01-01', 'yyyy-mm-dd') or
end_time >= nowTime); --(select to_char(end_time, 'mm') from dual) >= '07'); --续费用户退订总人数
select count(*)
into returns
from ord_order
where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) = '05'
and end_time between nowTime and nowTime2; --(select to_char(end_time, 'mm') from dual) = '07'; --续费用户激活未退订
select count(*)
into noActiveReturn
from ord_order
where AGREE_TO_TIME between orderDate and orderDate2 -- (select to_char(AGREE_TO_TIME, 'mm') from dual) = '06'
and end_time between nowTime and nowTime2 --(select to_char(end_time, 'mm') from dual) = '07'
and BECOME_EFFECTIVE_TIME < nowTime --to_date('2009-07-01', 'yyyy-mm-dd')
and BECOME_EFFECTIVE_TIME = to_date('1900-01-01', 'yyyy-mm-dd'); -- 当前报表月在个月激活的人数
select count(*)
into reportDateActive
from ord_order
where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) = '05'
and (end_time = to_date('1900-01-01', 'yyyy-mm-dd') or
end_time >= nowTime) --(select to_char(end_time, 'mm') from dual) >= '06')
and BECOME_EFFECTIVE_TIME between nowTime and nowTime2; --(select to_char(BECOME_EFFECTIVE_TIME, 'mm') from dual) = '06'; -----------------------------之前经过校验得到正确结果---------------------
--续费用户报表月激活人数
select count(*)
into active
from ord_order
where AGREE_TO_TIME between orderDate and orderDate2 --(select to_char(AGREE_TO_TIME, 'mm') from dual) = '04'
and BECOME_EFFECTIVE_TIME != to_date('1900-01-01', 'yyyy-mm-dd')
and BECOME_EFFECTIVE_TIME < nowTime --(select to_char(BECOME_EFFECTIVE_TIME, 'mm') from dual) < '07'
and ((end_time = to_date('1900-01-01', 'yyyy-mm-dd')) or
end_time >= nowTime); --(select to_char(end_time, 'mm') from dual) >= '07'); activeReturn := returns - noActiveReturn; noActive := renew - active - reportDateActive; --做插入操作
insert into report_pc51
(REPORTDATE,
ORDERDATE,
RENEW,
RETURNS,
NOACTIVERETURN,
REPORTDATEACTIVE,
ACTIVERETURN,
ACTIVE,
NOACTIVE)
values
(nowTime,
orderDate,
renew,
returns,
noActiveReturn,
reportDateActive,
activeReturn,
active,
noActive); dbms_output.put_line(i);
end loop; COMMIT; 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. IDG合伙人李丰:O2O中的C2C蕴藏巨大商机

    [ 亿欧导读 ] IDG合伙人李丰表示,每个新趋势出现,都是在解决上一轮行业革新时没有解决好的市场需求.而O2O中的C2C将会出现巨大商机的原因在于移动互联网的出现创造了新的交互方式,可以更快速的匹配 ...

  2. 【转载】Android开发学习笔记:Intent的简介以及属性的详解

    http://liangruijun.blog.51cto.com/3061169/634411/ 一.Intent的介绍 Intent的中文意思是“意图,意向”,在Android中提供了Intent ...

  3. github 学习笔记【一】

    这几天在学习github ,其实学了主要用来管理自己的项目!因为要在家里和公司两头做! 所以就开始学习使用!目前熟练几个命令,其他的一边用一遍学吧!想一举成功应该是不太可能的! 反复记忆才能更好,据说 ...

  4. Centos与win8.1的双系统

      背景:win8.1系统已经安装完成,并在此基础之上使用光盘或者U盘来安装centos系统,最终实现双系统   1.         在win8.1系统下查看磁盘及分区情况   2.         ...

  5. 20150515--关于IIS的备忘(WIN7)

    一.IIS服务位置: 1)控制面板--程序和功能 2)点击打开或关闭Windows功能, 3)Internet服务信息(英文:internet information services)--Web管理 ...

  6. 20140213-想念是while里的死循环

    // stdafx.h : 标准系统包含文件的包含文件,// 或是经常使用但不常更改的// 特定于项目的包含文件// #pragma once#include "targetver.h&qu ...

  7. java面试题小全

    面向对象的特征有哪些方面   1. 抽象:抽象就是忽略一个主题中与当前目标2. 无关的那些方面,3. 以便更充分地注意与当前目标4. 有关的方面.抽象并不5. 打算了解全部问题,而6. 只是选择其中的 ...

  8. Linux 输入子系统

    Technorati 标签: Kernel 输入子系统 Input      在Linux中,输入设备(如按键.键盘.触摸屏.鼠标等)是典型的字符设备,其一般的工作机理,是底层在按键.触摸时,触发一个 ...

  9. 一步一步学习C++

    根据<C++ primer>第五版 总结学习心得. 在实践中,不必全面地使用C++语言的各种特性,而应根据工程的实际情况,适当取舍(譬如动态类型信息,虚拟继承.异常等特性的使用,很值得商榷 ...

  10. 【风马一族_git_github】git的工作流程

    git有三个区域(如图): 基本信息设置 1)设置用户名   git config --global user.name  "帐号名" 2)设置用户名邮箱  git config ...