摘要:Oracle存储过程对于Oracle数据库中的重要性毋庸置疑,下面就为您介绍一个Oracle存储过程的使用实例,希望对您学习Oracle存储过程有更多的了解…… |
最近在写一个项目中所用的Oracle存储过程,由于是第一次接触oracle,其间花费了许多功夫,才把功能实现!特记录下来,以供参考.
以下是代码片段:
createorreplacepackagePSH_GPRSSTREAMSTATis
--Author:ADMINISTRATOR
--Created:2004-12-810:56:01
--Purpose:GPRS流量统计状态
--统计GPRS流量
type
C_Curisrefcursor;
functionCalcu_GPRSSTREAMreturnnumber;
endPSH_GPRSSTREAMSTAT;
-----------------------------------------------------------------------------
createorreplacepackagebodyPSH_GPRSSTREAMSTATis
functionCalcu_GPRSSTREAMreturnnumber
is
c_IPPackHeadLenconstantnumber:=40;--定义IP包头长度
CURSORc_SPINFOis
selectdistinctspidfromsh_spinfowhereisactive='0';
c_MDTINFOC_Cur;
v_MDTINFOnumber;
v_UpTransContentLensnumber(20,0);--存放当前GPRS终端上传转发的信息内容长度
v_UpContentLensnumber(20,0);
v_UpTotalLensnumber(20,0);--累计GPRS终端上传的信息内容长度
v_DownContentLensnumber(20,0);
v_DownTotalLensnumber(20,0);
newIDnumber(20,0);
begin
--初始化
以下是代码片段:
selectmax(statid)intonewIDfromsh_gprsstreamstat;
if(newIDisnull)then
newID:=1;
endif;
forv_SPINFOInc_SPINFOloop--首先获取SPID
--其次遍历出与当前SPID对应的所有MDT
以下是代码片段:
openc_MDTINFoforselectdistinctmdtidfromsh_mdtinfowhere(isactive='0')and(spid=v_SPINFO.spid);
loop
fetchc_MDTINFOintov_MDTINFO;
exitwhenc_MDTINFO%notfound;
v_UpContentLens:=0;
v_UpTransContentLens:=0;
v_UpTotalLens:=0;
v_DownContentLens:=0;
v_DownTotalLens:=0;
相关消息:Oracle大数据设备贴牌Cloudera解决方案
Oracle代码的执行效率之编译器的威力
Oracle代码的执行效率之算法是关键
Oracle的安全标记算不算bug
oracle写满磁盘空间解决步骤
oracle游标和游标变量的区别
Oracle游标常用属性
Oracleexport数据自动压缩
关于oracle中like的优化
浅析Oracle备份方式差异性
--下面两个select语句是用来获得GPRS终端上传的信息流量
以下是代码片段:
selectsum(length(content)+c_IPPackHeadLen)intov_UpContentLensfromsh_gprsmdtupinfowhere(MDTID=v_MDTINFO)and(spid=v_SPINFO.spid);
selectsum(length(content)+c_IPPackHeadLen)intov_UpTransContentLensfromsh_gprsmdttransinfowhere(issuccess='1')and(MDTID=v_MDTINFO)and(spid=v_SPINFO.spid);
if(v_UpContentLensisnull)then
v_UpContentLens:=0;
endif;
if(v_UpTransContentLensisnull)then
v_UpTransContentLens:=0;
endif;
v_UpTotalLens:=v_UpTotalLens+v_UpContentLens+v_UpTransContentLens;
--下面的Select语句是用来获得服务商下发的信息流量
以下是代码片段:
selectsum(length(content)+c_IPPackHeadLen)intov_DownContentLensfromsh_gprsspdowninfowhere(MDTID=v_MDTINFO)and(spid=v_SPINFO.spid);
if(v_DownContentLensisnull)then
v_DownContentLens:=0;
endif;
v_DownTotalLens:=v_DownTotalLens+v_DownContentLens;
--将统计出的累计值存放到流量状态统计表中
以下是代码片段:
if(v_UpTotalLens>0)or(v_DownTotalLens>0)then
insertintosh_gprsstreamstat(statid,spid,mdtid,starttime,endtime,mdtupstream,spdownstream)
values(newID,v_SPINFO.spid,v_MDTINFO,sysdate,sysdate,v_UpTotalLens,v_DownTotalLens);
--自增量加1
以下是代码片段:
newID:=newID+1;
endif;
endloop;
closec_MDTINFO;
commit;
endloop;
return1;
end;
begin
null;
endPSH_GPRSSTREAMSTAT;
责任编辑:yolanda