`
郑云飞
  • 浏览: 821321 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

那些年我写过的oracle存储过程和计划任务

 
阅读更多

前言:   

    那些年我写过的存储过程和计划任务,先将其写成博客,归纳总结,方便以后查看。

目录:

   1. 创建绑定用户数存储过程

   2. 创建业务统计数据存储过程

   3. 创建访问量存储过程

   4. 计划任务:明天0晨执行定时任务

   5. 创建注册用户数存储过程

   6. 创建计划任务:明天凌晨定时执行存储过程

   7. 相似博客推荐

 

---------------------全局库--------------------------------
1:创建绑定用户数存储过程
create or replace procedure bind_statis_pro is
begin
  delete from w_bind_statistics@dbltest;
  insert into w_bind_statistics@dbltest
    select t.organ_code,
           '01',
           to_date(to_char(t.bind_time, 'yyyy-mm-dd'), 'yyyy-mm-dd'),
           count(0)
      from w_busi_user_bind t
     where to_char(t.bind_time, 'yyyy-mm-dd') <
           to_char(sysdate, 'yyyy-mm-dd')
     group by t.organ_code, to_char(t.bind_time, 'yyyy-mm-dd');
  commit;
end;

2:创建业务统计数据存储过程

create or replace procedure busi_statis_pro is
begin
  delete from w_busi_statistics@dbltest;
  insert into w_busi_statistics@dbltest
    select s.area_no,
           '01',
           to_date(s.req_date, 'yyyy-mm-dd'),
           nvl(a.count, 0),
           nvl(b.count, 0),
           nvl(c.count, 0),
           nvl(d.count, 0),
           nvl(e.count, 0),
           nvl(f.count, 0),
           nvl(g.count, 0)
    
      from (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   count(0) count
              from pub_queue_app a
             where to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no, to_char(a.req_date, 'yyyy-mm-dd')) S,
           
           (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   a.type_code,
                   count(0) count
              from pub_queue_app a
             where a.type_code = '001'
               and to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no,
                      to_char(a.req_date, 'yyyy-mm-dd'),
                      a.type_code) A,
           
           (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   a.type_code,
                   count(0) count
              from pub_queue_app a
             where a.type_code = '003'
               and to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no,
                      to_char(a.req_date, 'yyyy-mm-dd'),
                      a.type_code) B,
           
           (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   a.type_code,
                   count(0) count
              from pub_queue_app a
             where a.type_code = '005'
               and to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no,
                      to_char(a.req_date, 'yyyy-mm-dd'),
                      a.type_code) C,
           
           (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   a.type_code,
                   count(0) count
              from pub_queue_app a
             where a.type_code = '006'
               and to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no,
                      to_char(a.req_date, 'yyyy-mm-dd'),
                      a.type_code) D,
           
           (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   a.type_code,
                   count(0) count
              from pub_queue_app a
             where a.type_code = '007'
               and to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no,
                      to_char(a.req_date, 'yyyy-mm-dd'),
                      a.type_code) E,
           
           (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   a.type_code,
                   count(0) count
              from pub_queue_app a
             where a.type_code = '008'
               and to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no,
                      to_char(a.req_date, 'yyyy-mm-dd'),
                      a.type_code) F,
           
           (select a.area_no,
                   to_char(a.req_date, 'yyyy-mm-dd') req_date,
                   a.type_code,
                   count(0) count
              from pub_queue_app a
             where a.type_code = '009'
               and to_char(a.req_date, 'yyyy-mm-dd') <
                   to_char(sysdate, 'yyyy-mm-dd')
             group by a.area_no,
                      to_char(a.req_date, 'yyyy-mm-dd'),
                      a.type_code) G
    
     where s.area_no = a.area_no(+)
       and s.area_no = b.area_no(+)
       and s.area_no = c.area_no(+)
       and s.area_no = d.area_no(+)
       and s.area_no = e.area_no(+)
       and s.area_no = f.area_no(+)
       and s.area_no = g.area_no(+)
       and s.req_date = a.req_date(+)
       and s.req_date = b.req_date(+)
       and s.req_date = c.req_date(+)
       and s.req_date = d.req_date(+)
       and s.req_date = e.req_date(+)
       and s.req_date = f.req_date(+)
       and s.req_date = g.req_date(+)
     order by to_date(s.req_date, 'yyyy-mm-dd') desc;

  commit;
end;

3:创建访问量存储过程

create or replace procedure visit_statis_pro is
begin
  delete from w_visit_statistics@dbltest;
  insert into w_visit_statistics@dbltest
    select '01',
           to_date(to_char(t.visit_first_action_time, 'yyyy-mm-dd'),
                   'yyyy-mm-dd'),
           sum(t.visit_total_actions)
      from w_log_visit t
     where to_char(t.visit_first_action_time, 'yyyy-mm-dd') <
           to_char(sysdate, 'yyyy-mm-dd')
     group by to_char(t.visit_first_action_time, 'yyyy-mm-dd');
  commit;
end;

4:计划任务:明天0晨执行定时任务

declare
  v_job number;
begin
  sys.dbms_job.submit( v_job,
                       'bind_statis_pro;busi_statis_pro;visit_statis_pro;',
                      sysdate,
                       'sysdate+1');
											 
	commit;
end;


---------------------------------用户库----------------------------------------------------
5:创建注册用户数存储过程
create or replace procedure regist_statis_pro is
begin
  insert into w_regist_statistics@dbltest
    select t.area_no,
           '01',
           to_date(to_char(t.reg_date, 'yyyy-mm-dd'), 'yyyy-mm-dd'),
           count(0)
      from w_users t
     where to_char(t.reg_date, 'yyyy-mm-dd') <
           to_char(sysdate, 'yyyy-mm-dd')
    
     group by t.area_no, to_char(t.reg_date, 'yyyy-mm-dd');

  commit;
end;

6:创建计划任务:明天凌晨定时执行存储过程

declare
  v_job number;
begin
  sys.dbms_job.submit( v_job,
                       'regist_statis_pro;',
                      sysdate,
                       'sysdate+1');
											 
	commit;
end;

   7.相似博客推荐

      1:那些年我写过的存储过程与计划任务

 
分享到:
评论

相关推荐

    利用windows任务计划调用oracle存储过程

    结合Oracle数据库,我们可以利用任务计划程序调用Oracle存储过程,实现定时的数据处理、备份或其他业务逻辑。本文将深入探讨如何实现这一功能。 首先,理解Oracle存储过程是关键。存储过程是预编译的SQL和PL/SQL...

    oracle存储过程解锁

    以下是对“oracle存储过程解锁”这一主题的深入解析。 ### 标题:“oracle存储过程解锁” #### 解析: 在Oracle数据库中,存储过程是一种预先编译并存储在数据库中的SQL代码块,用于执行复杂的业务逻辑或数据处理...

    Oracle存储过程中任务和管道的应用

    Oracle 存储过程中任务和管道的应用 Oracle 存储过程中任务和管道的应用是指在 Oracle 数据库中使用任务和管道来异步调用存储过程的方法。这种方法可以解决客户端调用存储过程后长时间没有反应的问题,并且可以实时...

    oracle存储过程+日期+定时任务Job

    ### Oracle 存储过程 + 日期 + 定时任务 Job #### 一、概述 在 Oracle 数据库中,存储过程是一种可编程的对象,用于执行特定的任务。存储过程可以在数据库服务器上运行,从而提高应用程序的性能并减少网络流量。...

    oracle存储过程-帮助文档

    Oracle存储过程是数据库管理系统中的一种重要特性,它允许开发者编写一系列SQL语句和PL/SQL块,形成可重复使用的代码单元。这篇博客“oracle存储过程-帮助文档”可能提供了关于如何创建、调用和管理Oracle存储过程...

    oracle 存储过程批量提交

    ### Oracle存储过程批量提交知识点详解 在Oracle数据库中,存储过程是一种重要的数据库对象,它可以包含一系列SQL语句和控制流语句,用于实现复杂的业务逻辑处理。存储过程不仅可以提高应用程序性能,还可以确保...

    Oracle存储过程返回结果集

    总结来说,Oracle存储过程通过`OUT`参数和`SYS_REFCURSOR`类型能够方便地返回结果集。在Java应用中,我们可以使用JDBC的`CallableStatement`和`ResultSet`来调用存储过程并处理返回的结果。这种方式在处理大量数据或...

    访问ORACLE存储过程

    在.NET环境中,访问Oracle存储过程是一项常见的任务,用于执行数据库中的复杂操作,如数据处理、事务管理和业务逻辑。本文将详细介绍如何使用OracleClient数据提供者在C#中调用存储过程,包括带输入、输出参数的存储...

    pb中执行oracle存储过程脚本

    在描述中提到的“使用批处理进行oracle存储过程脚本的创建和更新的处理”,这可能意味着开发者使用批处理命令(如Windows的批处理文件`.bat`)来自动化执行创建或更新Oracle存储过程的任务。批处理文件可以包含一...

    ORACLE存储过程学习源码

    Oracle存储过程是数据库编程的重要组成部分,它允许程序员在数据库中执行复杂的业务逻辑和数据操作。这个"ORACLE存储过程学习源码"集合包含了从基础到高级的30个示例,是学习和掌握Oracle存储过程的理想资源。下面,...

    C# 传入自定义列表List 到Oracle存储过程

    本文将详细讲解如何在C#中使用自定义列表(List)作为参数调用Oracle存储过程,以及实现这一功能的关键技术和注意事项。 首先,我们需要了解Oracle数据库中的PL/SQL类型,例如VARCAR2、NUMBER等,它们对应于C#中的...

    Oracle存储过程调用bat批处理脚本程序

    首先,`Oracle存储过程`是一种预编译的SQL和PL/SQL代码集合,可以被多次调用以执行特定的任务。它们提高了性能,降低了网络流量,并简化了数据库管理。在存储过程中调用外部脚本可以扩展Oracle的功能,比如自动化...

    oracle 定时任务,使用存储过程更新数据

    在本主题中,我们将深入探讨如何利用Oracle的存储过程来创建和管理定时任务。 首先,Oracle中的定时任务通常通过“调度器”(DBMS_SCHEDULER)来实现。这个包提供了丰富的功能,允许用户定义任务、设置执行时间、...

    Oracle定时执行存储过程

    oracle 是一个功能强大的关系型数据库管理系统,可以执行各种复杂的任务,其中包括定时执行存储过程。定时执行存储过程可以让 oracle 自动执行某些操作,而不需要人工干预。下面我们将详细讲解 oracle 中的定时执行...

    Oracle自动备份存储过程脚本及过程详解

    ### Oracle自动备份存储过程脚本及过程详解 #### 一、背景介绍 在数据库管理过程中,为了确保数据的安全性与可恢复性,...通过以上步骤,我们可以实现Oracle存储过程的自动化备份,极大地提高了数据库维护的工作效率。

    C#中调用oracle存储过程返回数据集

    在C#中调用Oracle存储过程来返回数据集是一个常见的任务,这涉及到ADO.NET库的使用,特别是OracleClient组件。Oracle存储过程是数据库中的预编译SQL代码块,可以接收输入参数,执行复杂的业务逻辑,并返回结果。在C#...

    oracle存储过程学习资料

    Oracle存储过程是数据库管理系统Oracle中的一个重要特性,它允许开发者编写一系列复杂的SQL和PL/SQL语句,形成可重用的代码块。这些代码块可以执行数据处理、事务控制、错误处理等多种任务,极大地提高了数据库应用...

    oracle存储过程例子

    Oracle存储过程是数据库管理系统Oracle中的一种重要特性,它允许开发者编写包含了一系列SQL和PL/SQL语句的程序单元,用于执行特定的任务。在数据库管理、数据处理和业务逻辑实现方面,存储过程扮演着不可或缺的角色...

Global site tag (gtag.js) - Google Analytics