Home > Database > Mysql Tutorial > Oracle 存储过程实例备忘

Oracle 存储过程实例备忘

WBOY
Release: 2016-06-07 16:42:35
Original
1110 people have browsed it

Oracle 存储过程实例备忘 统计报表:用户登录量(平台点击量)每月月初定时任务统计前一个月的登陆次数、登陆账号数、账号总数。

Oracle 存储过程实例备忘

统计报表:用户登录量(平台点击量)每月月初定时任务统计前一个月的登陆次数、登陆账号数、账号总数。

使用存储过程把查询的值存储到表 RP_MONTH_CLICK 中。

create or replace procedure update_RP_MONTH_CLICK  as
  --定义变量
  date_v varchar(6);                --年月             
  login_count_v INTEGER;            --登录次数
  login_accoun_count_v INTEGER;    --登录账号数           
  accoun_count_v INTEGER;          --账号总数
  begin
  /* ------------------ 获取参数 用into关键字赋值给变量 start--------------------- */ 
      --年月
      select case WHEN to_char(sysdate-1,'YYYYMM')=to_char(sysdate,'YYYYMM') THEN to_char(sysdate,'YYYYMM')
      else to_char(sysdate-1,'YYYYMM') end into date_v from dual ;
        --登录次数
      select count(t.log_id) into login_count_v from SC_ACT_LOG t where t.act_type = 5
      and TO_DATE(TO_CHAR(t.act_time, 'YYYYMM'), 'YYYYMM') = TO_DATE(TO_CHAR(SYSDATE, 'YYYYMM'), 'YYYYMM');
     
      --登录账号数
      select  count(staff_id) into login_accoun_count_v from (
          select t.staff_id from SC_ACT_LOG t where t.act_type = 5
          and TO_DATE(TO_CHAR(t.act_time, 'YYYYMM'), 'YYYYMM') = TO_DATE(TO_CHAR(SYSDATE, 'YYYYMM'), 'YYYYMM')
          group by t.staff_id
        );
      -- 账号总数
    select count(t.staff_id) into accoun_count_v from HRM_STAFF t where t.status = 1 ;
  /* ------------------ 获取参数 end--------------------- */   
  --先删除
  delete from RP_MONTH_CLICK where RMONTH = date_v ;
  --再添加
  insert into RP_MONTH_CLICK ( ID, RMONTH,LOGIN_COUNT,LOGIN_ACCOUNT_COUNT,ACCOUNT_COUNT )
  values( SEQ_SC_GLOBAL_PARAMETERS.NEXTVAL,date_v,login_count_v,login_accoun_count_v,accoun_count_v);       
  commit;
  end;


 

本文永久更新链接地址:

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template