`
shihuan830619
  • 浏览: 582817 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

几个Oracle procedure实例

阅读更多
create or replace procedure PC_TB_HTTPTASK_RESULT_TMP IS
v_http_targetalias varchar2(300);
v_http_dns_avgrtt number;
v_http_avgrtt number;
v_http_firstbyte_avgrtt number;
v_http_body_avgrtt number;
v_http_avgspeed number;
v_http_pagesize number;
v_http_opentimertt NUMBER;

CURSOR c_httptask_result IS
SELECT HTTP_TARGETALIAS,
       AVG(HTTP_DNS_AVGRTT) HTTP_DNS_AVGRTT,
       AVG(HTTP_AVGRTT) HTTP_AVGRTT,
       AVG(HTTP_FIRSTBYTE_AVGRTT) HTTP_FIRSTBYTE_AVGRTT,
       AVG(HTTP_BODY_AVGRTT) HTTP_BODY_AVGRTT,
       AVG(HTTP_AVGSPEED) HTTP_AVGSPEED,
       MAX(HTTP_PAGESIZE) HTTP_PAGESIZE
FROM (SELECT OBJECTID,
       HTTP_TARGETALIAS,
       HTTP_DNS_AVGRTT,
       HTTP_AVGRTT,
       HTTP_FIRSTBYTE_AVGRTT,
       HTTP_BODY_AVGRTT,
       HTTP_AVGSPEED,
       HTTP_PAGESIZE
  FROM TB_HTTPTASK_RESULT
WHERE
   TO_CHAR(COLTIME, 'YYYY-MM-DD') = TO_CHAR(SYSDATE-1, 'YYYY-MM-DD')
   AND HTTP_TARGETALIAS IS NOT NULL) TB_HTTPTASK_RESULT_CON
   
  WHERE
   OBJECTID IN
       (SELECT GROUPTASKID
          FROM GROUPTASK
         WHERE GROUPTASKID IN
               (SELECT TASKID
                  FROM GROUPTASKRELATION
                 WHERE GROUPID IN
                       (SELECT PROBEGROUPID
                          FROM TB_TASK_INFO
                         WHERE ID IN
                               (SELECT TASK_ID
                                  FROM TB_TASK_RELATION
                                 WHERE GROUP_ID IN
                                       (SELECT ID
                                          FROM TB_TASK_GROUP
                                         WHERE GROUPNAME = '宽带感知任务')))))
GROUP BY HTTP_TARGETALIAS;
/*
SELECT HTTP_TARGETALIAS,
       AVG(HTTP_DNS_AVGRTT) HTTP_DNS_AVGRTT,
       AVG(HTTP_AVGRTT) HTTP_AVGRTT,
       AVG(HTTP_FIRSTBYTE_AVGRTT) HTTP_FIRSTBYTE_AVGRTT,
       AVG(HTTP_BODY_AVGRTT) HTTP_BODY_AVGRTT,
       AVG(HTTP_AVGSPEED) HTTP_AVGSPEED,
       MAX(HTTP_PAGESIZE) HTTP_PAGESIZE
FROM TB_HTTPTASK_RESULT
WHERE OBJECTID IN
       (SELECT GROUPTASKID
          FROM GROUPTASK
         WHERE GROUPTASKID IN
               (SELECT TASKID
                  FROM GROUPTASKRELATION
                 WHERE GROUPID IN
                       (SELECT PROBEGROUPID
                          FROM TB_TASK_INFO
                         WHERE ID IN
                               (SELECT TASK_ID
                                  FROM TB_TASK_RELATION
                                 WHERE GROUP_ID IN
                                       (SELECT ID
                                          FROM TB_TASK_GROUP
                                         WHERE GROUPNAME = '宽带感知任务')))))
AND HTTP_TARGETALIAS IS NOT NULL
AND TO_CHAR(COLTIME, 'YYYY-MM-DD') = TO_CHAR(SYSDATE-1, 'YYYY-MM-DD')
GROUP BY HTTP_TARGETALIAS;
*/

-- SELECT * FROM TB_PERF_METRIC WHERE met_name LIKE 'HTTP_BODY_AVGRTT';

/******************************************************************************
   NAME:       PC_TB_HTTPTASK_RESULT_TMP
   PURPOSE:

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2010-11-10          1. Created this procedure.

   NOTES:

   Automatically available Auto Replace Keywords:
      Object Name:     PC_TB_HTTPTASK_RESULT_TMP
      Sysdate:         2010-11-10
      Date and Time:   2010-11-10, 10:54:32, and 2010-11-10 10:59:15
      Username:         (set in TOAD Options, Procedure Editor)
      Table Name:       (set in the "New PL/SQL Object" dialog)

******************************************************************************/
begin
  OPEN c_httptask_result;
  LOOP
  FETCH c_httptask_result INTO v_http_targetalias,
                               v_http_dns_avgrtt,
                               v_http_avgrtt,
                               v_http_firstbyte_avgrtt,
                               v_http_body_avgrtt,
                               v_http_avgspeed,
                               v_http_pagesize;
 
  EXIT WHEN c_httptask_result%NOTFOUND;
 
  v_http_opentimertt := v_http_dns_avgrtt + v_http_avgrtt + v_http_firstbyte_avgrtt + v_http_body_avgrtt;
  -- DELETE FROM TB_HTTPTASK_RESULT_TMP WHERE HTTP_TARGETALIAS = v_http_targetalias;
  INSERT INTO TB_HTTPTASK_RESULT_TMP(HTTP_TARGETALIAS,
                                     HTTP_DNS_AVGRTT,
                                     HTTP_AVGRTT,
                                     HTTP_FIRSTBYTE_AVGRTT,
                                     HTTP_BODY_AVGRTT,
                                     HTTP_AVGSPEED,
                                     HTTP_PAGESIZE,
                                     HTTP_OPENTIMERTT,
                                     CREATE_DATE)
  VALUES (v_http_targetalias,
          v_http_dns_avgrtt,
          v_http_avgrtt,
          v_http_firstbyte_avgrtt,
          v_http_body_avgrtt,
          v_http_avgspeed,
          v_http_pagesize,
          v_http_opentimertt,
          TRUNC(SYSDATE));
 
  END LOOP;
  COMMIT;
  EXCEPTION   
     WHEN OTHERS THEN  
         CLOSE c_httptask_result; 
         dbms_output.put_line(SQLERRM);
   IF c_httptask_result%ISOPEN THEN    
      CLOSE c_httptask_result;  
   END IF;
end PC_TB_HTTPTASK_RESULT_TMP;

----------------------------------------------------------------------

CREATE OR REPLACE PROCEDURE PC_TB_HTTPTASK_TIME120_RESULT IS
V_SYSDATE DATE DEFAULT SYSDATE;
V_HAS_DATA NUMBER;
V_HTTP_TARGETALIAS VARCHAR2(100);

/******************************************************************************
   NAME:       PC_TB_HTTPTASK_TIME120_RESULT
   PURPOSE:

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2011-03-03          1. Created this procedure.

   NOTES:

   Automatically available Auto Replace Keywords:
      Object Name:     PC_TB_HTTPTASK_TIME120_RESULT
      Sysdate:         2011-03-03
      Date and Time:   2011-03-03, 14:00:00, and 2011-03-03 14:00:00
      Username:         (set in TOAD Options, Procedure Editor)
      Table Name:       (set in the "New PL/SQL Object" dialog)

******************************************************************************/

CURSOR C_HTTP_TARGETALIAS IS
SELECT HTTP_TARGETALIAS_NAME FROM TB_HTTP_TARGETALIAS;

BEGIN
   
    BEGIN
      SELECT COUNT(*) INTO V_HAS_DATA FROM (SELECT HTTP_TARGETALIAS, AVG(HTTP_DNS_AVGRTT) HTTP_DNS_AVGRTT,MAX(HTTP_PAGESIZE) HTTP_PAGESIZE FROM TB_HTTPTASK_RESULT WHERE HTTP_TARGETALIAS IS NOT NULL AND COLTIME >= V_SYSDATE - INTERVAL '120' MINUTE AND COLTIME < V_SYSDATE AND OBJECTID IN (SELECT GROUPTASKID FROM GROUPTASK WHERE GROUPTASKID IN (SELECT TASKID FROM GROUPTASKRELATION WHERE GROUPID IN (SELECT PROBEGROUPID FROM TB_TASK_INFO WHERE ID IN (SELECT TASK_ID FROM TB_TASK_RELATION WHERE GROUP_ID IN (SELECT ID FROM TB_TASK_GROUP WHERE GROUPNAME = '宽带感知任务'))))) GROUP BY HTTP_TARGETALIAS) TB_HTTPTASK_RESULT_HAS_DATA;
      EXCEPTION
      WHEN no_data_found THEN
           V_HAS_DATA := 0;
    END;
   
    IF V_HAS_DATA=0 THEN
     
       OPEN C_HTTP_TARGETALIAS;
       LOOP
         FETCH C_HTTP_TARGETALIAS INTO V_HTTP_TARGETALIAS;
         EXIT WHEN C_HTTP_TARGETALIAS%NOTFOUND;
         INSERT INTO TB_HTTPTASK_WM_RESULT_TMP(HTTP_TARGETALIAS,HTTP_OPENTIMERTT,CREATE_DATE,HTTP_DNS_AVGRTT,HTTP_PAGESIZE) VALUES (V_HTTP_TARGETALIAS, 0, V_SYSDATE, 0, 0);
       END LOOP;
      
    ELSE
       INSERT INTO TB_HTTPTASK_WM_RESULT_TMP(HTTP_TARGETALIAS,HTTP_OPENTIMERTT,CREATE_DATE,HTTP_DNS_AVGRTT,HTTP_PAGESIZE) SELECT HTTP_TARGETALIAS, AVG(HTTP_DNS_AVGRTT+HTTP_AVGRTT+HTTP_FIRSTBYTE_AVGRTT+HTTP_BODY_AVGRTT) HTTP_OPENTIMERTT, V_SYSDATE, AVG(HTTP_DNS_AVGRTT) HTTP_DNS_AVGRTT, MAX(HTTP_PAGESIZE) HTTP_PAGESIZE FROM TB_HTTPTASK_RESULT WHERE HTTP_TARGETALIAS IS NOT NULL AND COLTIME >= V_SYSDATE - INTERVAL '120' MINUTE AND COLTIME < V_SYSDATE AND OBJECTID IN (SELECT GROUPTASKID FROM GROUPTASK WHERE GROUPTASKID IN (SELECT TASKID FROM GROUPTASKRELATION WHERE GROUPID IN (SELECT PROBEGROUPID FROM TB_TASK_INFO WHERE ID IN (SELECT TASK_ID FROM TB_TASK_RELATION WHERE GROUP_ID IN (SELECT ID FROM TB_TASK_GROUP WHERE GROUPNAME = '宽带感知任务'))))) GROUP BY HTTP_TARGETALIAS;
    END IF;
 
    COMMIT;
   
    EXCEPTION
      WHEN OTHERS THEN
        CLOSE C_HTTP_TARGETALIAS;
        DBMS_OUTPUT.PUT_LINE(SQLERRM);
        IF C_HTTP_TARGETALIAS%ISOPEN THEN    
          CLOSE C_HTTP_TARGETALIAS;  
       END IF;
 
END PC_TB_HTTPTASK_TIME120_RESULT;
分享到:
评论

相关推荐

    Oracle PLSQL实例精解(原书第4版) 源码下载

    学习Oracle PL/SQL,你需要掌握以下几个核心知识点: 1. **基础语法**:包括变量声明、条件语句(IF-THEN-ELSIF, CASE)、循环结构(WHILE, FOR, LOOP)、异常处理(BEGIN-EXCEPTION-END)等。 2. **数据类型**:...

    oracle存储过程学习经典(实例)

    学习Oracle存储过程主要涉及以下几个核心知识点: 1. **定义与结构**:存储过程由一个或多个SQL和PL/INSQL语句组成,包括输入参数、输出参数和过程体。例如,`CREATE OR REPLACE PROCEDURE proc_name (param1 ...

    oracle语句实例大全

    在Oracle SQL中,有以下几个核心知识点: 1. **数据查询**:SQL的SELECT语句是用于从数据库中检索数据的基本工具。例如,`SELECT * FROM table_name` 可以获取表中的所有数据,而 `SELECT column1, column2 FROM ...

    oracle进阶实例代码

    根据提供的标题、描述、标签及部分内容,我们可以提炼出Oracle数据库中的几个重要的知识点,这些知识点主要集中在存储过程(Stored Procedure)与函数(Function)的创建与使用上,同时也涉及到了游标(Cursor)的...

    ibatis+oracle实例

    在实际项目中,Ibatis与Oracle的结合使用主要体现在以下几个方面: 1. **SQL调优**:Ibatis允许直接编写原生的SQL,便于充分利用Oracle的特性进行性能优化。 2. **事务管理**:Ibatis提供了对数据库事务的控制,...

    oracle存储过程学习经典[语法+实例+调用]

    在语法层面,Oracle存储过程主要由以下几个部分组成: 1. **CREATE PROCEDURE**:创建存储过程的语句,用于定义存储过程的名称和参数。 2. **参数声明**:在存储过程中,可以声明输入参数、输出参数或双向参数,用于...

    Oracle JOB,procedure,cursor 的使用

    创建一个Oracle JOB通常涉及以下几个步骤:定义作业(DBMS_SCHEDULER.CREATE_JOB),指定执行时间(DBMS_SCHEDULER.SET_ATTRIBUTE),启动作业(DBMS_SCHEDULER.RUN_JOB),以及监控和管理作业状态(DBMS_SCHEDULER....

    oracle 的函数、存储过程、游标、简单实例

    本主题将深入探讨Oracle中的几个核心概念:函数、存储过程、游标以及简单的实例,这些都是数据库管理员和开发人员日常工作中不可或缺的部分。 首先,我们来了解**Oracle函数**。函数是预定义的代码块,接受零个或多...

    Oracle中job的实例

    在创建Job时,需要指定几个关键参数: 1. **Job No**: 这是一个由`dbms_job.submit()`过程返回的`BINARY_INTEGER`类型值,用于唯一标识一个Job。 2. **What**: 指将要执行的PL/SQL代码块。 3. **Next Date**: 表示...

    .net连接oracle的简单实例——学生、教师、课程管理系统。

    我们将主要关注以下几个方面: 1. **Oracle数据库连接**: .NET应用程序通过ADO.NET框架与Oracle数据库进行交互。首先,需要安装Oracle客户端和ODP.NET(Oracle Data Provider for .NET)驱动程序,这是Oracle提供的...

    Oracle存储过程开发的要点

    在Oracle存储过程开发中,你需要掌握以下几个关键步骤: 1. 使用文本编辑器(如Notepad)编写存储过程的PL/SQL代码。 2. 在Oracle数据库中创建存储过程,这通常通过发出`CREATE OR REPLACE PROCEDURE` SQL语句来完成...

    oracle创建表空间实例代码

    下面是几个具体的例子: - **临时表空间**: ```sql CREATE TEMPORARY TABLESPACE test_temp TEMPFILE 'C:\oracle\product\10.1.0\oradata\orcl\test_temp01.dbf' SIZE 32M AUTOEXTEND ON NEXT 32M MAXSIZE ...

    oracle中建存储过程的具体实现实例(供初学者使用)

    下面将详细介绍几个具体的存储过程示例及其用途: ##### 1. 创建表 `t_user` ```sql CREATE TABLE t_user ( id NUMBER(4) PRIMARY KEY, uname VARCHAR2(20), age NUMBER(3) ); ``` 此表用于存储用户的基本信息...

    oracle存储过程学习经典[语法+实例+调用

    Oracle存储过程是构建在Oracle数据库中的一个独立的代码块,能够封装复杂的业务逻辑,让程序逻辑转移到数据库层面执行,从而提高数据处理效率和减少网络传输数据量。Oracle存储过程可以包含SQL语句、PL/SQL块、Java...

    oracle数据库各种功能语句以及驱动

    例如,你可以创建一个存储过程`CREATE OR REPLACE PROCEDURE my_procedure IS BEGIN ... END;`,并在其中实现复杂的业务逻辑。 3. 视图(View):视图是基于一个或多个表的虚拟表,可以简化复杂查询并提供数据安全...

    oracle存储过程笔记

    首先,存储过程有以下几个显著特点: 1. **预编译与优化**:存储过程在创建时会被预编译并存储在SQL内存中,执行时无需再次编译,从而提高了执行效率。 2. **减少网络流量**:过程的代码直接存储在数据库中,客户端...

    oracle汉字转拼音

    在给定的文件"oracle汉字转拼音package_获得全拼——拼音首字母_拼音截取等.sql"中,我们可以看到一个自定义的包,这个包可能包含了以下几个功能: 1. 获得全拼:将汉字转换为完整的拼音,包括声母、韵母和声调。 ...

    Springboot调用Oracle存储过程的几种方式.docx

    这种方式首先通过`entityManagerFactory`获取`SessionFactory`实例,然后打开一个新的`Session`。由于每次调用后都需要手动关闭`Session`来释放连接,否则当超过连接池的默认大小时,会导致新的数据库操作失败。...

Global site tag (gtag.js) - Google Analytics