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. 2075 yh女朋友的危机、2544 拯救小矮人

    Codevs2075和2544是一道题,直接A过. 2075 yh女朋友的危机  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果   ...

  2. Android OpenGL ES(二)----平滑着色

    直线或者三角形上的每个片段混合后的颜色可以用一个varying生成.我们不仅能混合颜色,还可以给varying传递任何值,OpenGL会选择属于那条直线的两个值,或者属于那个三角形的三个值,并平滑地在 ...

  3. 十一、Android学习笔记_AsyncQueryHandler的应用

    研究AsyncQueryHandler这个类的时候遇到了几个重要的不清楚的知识点 1. Handler与Thread,Looper的关系 2. HandlerThread是干什么用的 3. Threa ...

  4. Part 34 to 35 Talking about multiple class inheritance in C#

    Part 34 Problems of multiple class inheritance Part 35 Multiple class inheritance using interfaces

  5. JavaScript之动画2

    在JavaScript动画中,我们调用setInterval函数(setInterval动作的作用是在播放动画的时,每隔一定时间就调用函数,方法或对象),值得注意的是:setInterval它设置的时 ...

  6. Java之阶乘数的计算

    说起“阶乘数”,我们应该都不会感到陌生.当老师布置了这样的作业,我们大多数人是一贯用笔算,还有的同学会用计算机去计算.数学是讲究原理和方法的,我们知其然,也要知其所以然.下面我们就用编程来计算阶乘数. ...

  7. 零基础Android学习笔记-02 安卓程序生命周期

    一个安卓程序生命周期会经历7中状态,并不一定是每次都全部经历.Create,Start,ReStart,Pause,Resume,Stop,Destory. 重载方法,用helloWorld程序去体验 ...

  8. POJ 1273(EK)

    题目大概意思是,有N条水沟和M个水池,问从第一个水池到最后一个水池在同一时间内能够流过多少水第一行有两个整数N,M接下来N行,每行有3个整数,a,b,c,代表从a到b能够流c单位的水超级模板题,一个有 ...

  9. 关于CORS

    前几天碰到CORS问题,只要在“Access-Control-Allow-Origin”响应头中添加对应域名即可. 今天做一个上传文件的demo,利用XMLHttpRequest向服务器发送post请 ...

  10. 【转】使用Memcached提高.NET应用程序的性能

    在应用程序运行的过程中总会有一些经常需要访问并且变化不频繁的数据,如果每次获取这些数据都需要从数据库或者外部文件系统中去读取,性能肯定会受到影响,所以通常的做法就是将这部分数据缓存起来,只要数据没有发 ...