oracle pipelined返回值函数 针对数据汇总统计 返回结果集方法
/*打开日志输出*/
Set serveroutput on ;
/*创建类型*/
create or replace type type_flux_data_stat_o as object
(
ifinoctetsbps number ,
ifoutoctetsbps number ,
collecttime number
);
/*创建类型归属为表类型*/
create or replace type type_flux_data_stat as table of type_flux_data_stat_o;
/*pipelined创建函数 返回表类型*/
create or replace FUNCTION f_linkgroupstat(begin_time IN NUMBER,
end_time IN NUMBER,
lg_id in varchar2,
table_name varchar2 )
return type_flux_data_stat
pipelined as
/*游标申明*/
v_Cur SYS_REFCURSOR ;
/*sql临时变量*/
v_SQLStatement string (10000 );
/*表类型*/
v_Table type_flux_data_stat_o;
/*流入字节数临时变量*/
tmp_ifinoctetsbps NUMBER ;
/*流出字节数临时变量*/
tmp_ifoutoctetsbps NUMBER ;
/*流入字节数汇总*/
total_ifinoctetsbps NUMBER ;
/*流出字节数汇总*/
total_ifoutoctetsbps NUMBER ;
/*起始时间窗格*/
tmp_begin_time NUMBER ;
/*结束时间窗格*/
tmp_end_time NUMBER ;
begin
/*时间窗格偏移量为5分钟(300秒)*/
tmp_begin_time := begin_time;
tmp_end_time := begin_time + 300 ;
total_ifinoctetsbps := 0 ;
total_ifoutoctetsbps := 0 ;
loop
exit when tmp_begin_time > end_time;
v_SQLStatement := 'select sum(ifinoctetsbps) ifinoctetsbps,sum(ifoutoctetsbps) ifoutoctetsbps from ' ||
table_name ||
' a where exists (select 1 from tm_linkgroup_cportdirection b where a.getway = b.getway and a.port_info=b.ifindex_info and lg_id in (' ||
lg_id ||
') and a.device_id = b.device_id ) and a.collecttime >=' ||
tmp_begin_time || ' and a.collecttime <=' ||
tmp_end_time || ' order by collecttime' ;
Dbms_Output.put_line(v_SQLStatement);
/*针对字符串sql打开游标*/
open v_Cur for v_SQLStatement;
tmp_begin_time := tmp_begin_time + 300 ;
tmp_end_time := tmp_end_time + 300 ;
total_ifinoctetsbps := 0 ;
total_ifoutoctetsbps := 0 ;
loop
/*将游标的值放入零食变量中*/
fetch v_Cur
into tmp_ifinoctetsbps, tmp_ifoutoctetsbps;
/*当游标中不存在值时跳出游标*/
EXIT WHEN v_Cur% NOTFOUND;
total_ifinoctetsbps := total_ifinoctetsbps + tmp_ifinoctetsbps;
total_ifoutoctetsbps := total_ifoutoctetsbps + tmp_ifoutoctetsbps;
end loop ;
/*单行记录初始化*/
v_Table := type_flux_data_stat_o(total_ifinoctetsbps,
total_ifoutoctetsbps,
tmp_begin_time);
/*将记录压入至结果集中*/
pipe row (v_Table);
/*关闭游标*/
close v_Cur;
end loop ;
Exception
when others then
Dbms_Output.put_line( Sqlerrm );
end f_linkgroupstat;
select * from table(f_linkgroupstat(1361980800,1362067200,'34','FLUX_DATA_2013_2_28')) a; 289 rows selected. Elapsed: 00:00:00.28
执行时间为:28ms
oracle pipelined返回值函数 针对数据汇总统计 返回结果集方法的更多相关文章
- c语言进阶4-有返回值函数
一. 从函数返回 从函数返回就是返回语句的第一个主要用途.在程序中,有两种方法可以终止函数的执行,并返回到调用函数的位置.第一种方法是在函数体中,从第一句一直执行到最后一句,当所有语句 ...
- c++中带返回值函数没写return能通过编译但运行时会出现奇怪问题
c++中带返回值函数没写return能通过编译但运行时会出现奇怪问题 例如: string myFunc(){ theLogics(); } 发现调用: myFunc(); 崩溃. 但调用: cout ...
- go语言基础之有参有返回值函数的使用
1.有参有返回值函数的使用 示例1: package main //必须 import "fmt" //go官方推荐写法 func MaxAndMin(a, b int) (max ...
- Python函数01/函数的初识/函数的定义/函数调用/函数的返回值/函数的参数
Python函数01/函数的初识/函数的定义/函数调用/函数的返回值/函数的参数 内容大纲 1.函数的初识 2.函数的定义 3.函数的调用 4.函数的返回值 5.函数的参数 1.函数初识 # def ...
- c语言main函数返回值、参数详解(返回值是必须的,0表示正常退出)
C语言Main函数返回值 main函数的返回值,用于说明程序的退出状态.如果返回0,则代表程序正常退出:返回其它数字的含义则由系统决定.通常,返回非零代表程序异常退出. 很多人甚至市面上的一些书籍,都 ...
- SpringMVC入门(二)—— 参数的传递、Controller方法返回值、json数据交互、异常处理、图片上传、拦截器
一.参数的传递 1.简单的参数传递 /* @RequestParam用法:入参名字与方法名参数名不一致时使用{ * value:传入的参数名,required:是否必填,defaultValue:默认 ...
- C++获取Lua全局变量和执行Lua多参数多返回值函数
C++代码: // LuaAndC.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #i ...
- SpringMVC(二)返回值设置、数据在域中的保存与SpringMVC案例
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一.返回值的设置 1.返回 String [1]返回 String 默认情况 @RequestMappi ...
- ASP.Net MVC 在ajax接收controller返回值为Json数据
首先,再次回忆一下ajax的标准用法:(这张图写的比较详细了)(转) 页面部分ajax代码: $.ajax({ url: "/Home/Login?account=&q ...
随机推荐
- bzoj1188
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1188 一道非常好的SG函数题,加深了对博弈论的理解. 以前做的SG函数的题,都是每个瓶子看成一 ...
- 能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而是可以按片自由搭配 | 36氪
能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而是可以按片自由搭配 | 36氪 能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而 ...
- android图标设计事宜
1.Launcher图标 图标的最佳宽高是48x48 dp. ldpi:36*36px,0.75倍密度,一般不用提供,系统会从hdpi取图缩小1倍. mdpi:48*48px, 1倍密度 hdpi:7 ...
- MYSQL中的语句
MYSQL中的语句 decimal(8,2):最多存10位数的数字,小数点后保存两位.如:999999.99
- std::remove_if
原型: #include <algorithm>forward_iterator remove_if( forward_iterator start, forward_iterator e ...
- SpringTest2
Spring 框架第二天 AOP切面编程 今天重点内容: 1. 什么是AOP ? AOP实现原理是怎样的? AOP相关术语 2. AOP底层实现 (了解) ----- JDK动态代理. Cglib动态 ...
- iOS_SN_Xcode内存泄露调试
用Xcode进行内存调试有两种方法: 1.静态方法 2.动态方法 静态方法是直接在Xcode的菜单栏中选择product-->analyze 如截图所示. 之后会看到Xcode的编译状态上会有如 ...
- table超过30个字段如何处理呢? bootstrap
样式: @media (max-width: 768px) { .table-supplier { width: 100%; height: 100%; margin-bottom: 12.75px; ...
- jQuery和DOM对象
html示例 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=" ...
- HDU 5904 - LCIS (BestCoder Round #87)
HDU 5904 - LCIS [ DP ] BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...