小例子,方便以后查阅.

包头需要声明:   type C_CURSOR is ref cursor;

procedure visitcount(in_date  number,
out_code out number,
out_desc out varchar2
) is
t_date number(8);
t_datepre number(8);
t_sql varchar2(2000);
t_tempcount number(8);
c_data C_CURSOR; v_cityname varchar(20);
v_visittime number(8);
v_visitcount number(8);
v_counttype number(8);
begin
if(in_date<=0) then
t_date:=to_number(trunc(sysdate)-1,'yyyymmdd');
t_datepre:=to_number(trunc(sysdate)-2,'yyyymmdd');
else
t_date:=in_date;
t_datepre:=to_number(to_char(to_date(in_date,'yyyy-mm-dd')-1,'yyyymmdd'));
end if;
--删除之前的数据
--select count(1) into t_tempcount from cn_visitcount
-- where visittime=t_date;
--if t_tempcount>0 then
delete from cn_visitcount
where visittime=t_date;
--end if; t_sql:='
select * from (
select cityname,'||t_date||' visittime,count(1) visitcount,1 counttype from
(
select
(
case
when cityid=68 then ''深圳''
when cityid=56 then ''广州''
end
)cityname,mobile,count(1) from cn_visitanalysis
where to_number(to_char(visittime,''yyyymmdd''))='||t_date||
' and (cityid=68 or cityid=56)
group by cityid,mobile
)
group by cityname';
t_sql:=t_sql||'
union all
select cityname,'||t_date||' visittime,count(1) visitcount,2 counttype from
(
select
(
case
when cityid=68 then ''深圳''
when cityid=56 then ''广州''
end
)cityname,mobile,count(1) from cn_visitanalysis
where to_number(to_char(visittime,''yyyymmdd''))='||t_date||
' and (cityid=68 or cityid=56)
and mobile not in (
select mobile from cn_visitanalysis
where to_number(to_char(visittime,''yyyymmdd''))<='||t_datepre||'
and (cityid=68 or cityid=56)
)
group by cityid,mobile
)
group by cityname)
order by cityname,visitcount desc';
--插入查询的数据
open c_data for t_sql;
loop
fetch c_data into v_cityname,v_visittime,v_visitcount,v_counttype ;
exit when c_data%notfound;
insert into cn_visitcount
(visitcountid, cityname, visitcount, visittime, counttype)
values
(seq_cn_visitcountid.nextval,v_cityname, v_visitcount, v_visittime, v_counttype);
end loop;
--备份每日的手机号
delete from cn_visitmobile where visittime=t_date;
insert into cn_visitmobile
select seq_cn_visitmobileid.nextval,mobile,cityid,visittime from
(
select mobile,cityid,to_number(to_char(visittime,'yyyymmdd')) visittime
from cn_visitanalysis
where to_number(to_char(visittime,'yyyymmdd'))=t_date
and (cityid=68 or cityid=56)
group by cityid,mobile,to_number(to_char(visittime,'yyyymmdd'))
)
commit; exception
when others then
out_desc:='sqlcode:'||sqlcode ||' err_message:' || sqlerrm;
begin
out_code:= -;
--out_description := '系统繁忙,请稍后再试!';
rollback;
--raise;
--错误日志
insert into cn_joblog(joblogid,procname,starttime,endtime,logtype,remark)
values(seq_cn_joblogid.Nextval,'fx114v01_cn_job.visitcount',sysdate,sysdate,'error',out_desc);
commit;
end
;
end visitcount;

Oracle异常处理,动态游标的更多相关文章

  1. orcle中如何使用动态游标来对变量进行赋值

    在oracle中动态游标的概念一般不常用,但有时根据客户的特殊业务,需要使用到动态游标来解决问题!在对于一条动态SQL语句而产生多条记录时,动态游标的使用将是一个很好的选择,具体参见如下在工作流项目中 ...

  2. 【Oracle】PL/SQL 显式游标、隐式游标、动态游标

    在PL/SQL块中执行SELECT.INSERT.DELETE和UPDATE语句时,Oracle会在内存中为其分配上下文区(Context Area),即缓冲区.游标是指向该区的一个指针,或是命名一个 ...

  3. oracle异常处理——ORA-01000:超出打开游标最大数

    oracle异常处理--ORA-01000:超出打开游标最大数https://www.cnblogs.com/zhaosj/p/4309352.htmlhttps://blog.csdn.net/u0 ...

  4. oracle学习笔记(二十二) REF 动态游标

    动态游标 定义语法 --声明 $cursor_name$ sys_refcursor --打开动态游标 open $cursor_name$ is 查询语句; --关闭游标 close $cursor ...

  5. oracle存储过程和游标的使用

    oracle存储过程和游标的使用 (2011-04-19 14:52:47) 转载▼ 游标: 用来查询数据库,获取记录集合(结果集)的指针,我们所说的游标通常是指显式游标,因此从现在起没有特别指明的情 ...

  6. 【转】Oracle 执行动态语句

    1.静态SQLSQL与动态SQL Oracle编译PL/SQL程序块分为两个种:其一为前期联编(early binding),即SQL语句在程序编译期间就已经确定,大多数的编译情况属于这种类型:另外一 ...

  7. Oracle系列之游标

    涉及到表的处理请参看原表结构与数据  Oracle建表插数据等等 游标: 1.目的 解决“ select * ”返回空.多行记录问题 但凡select,就可能多行结果集,也就需要用游标 2.原理 多行 ...

  8. oracle超过最大游标数异常分析(转贴)

    问题描述 Oracle 使用 OPEN_CURSORS 参数指定一个会话一次最多可以打开的游标的数量.超过此数量时,Oracle 将报告 ORA-01000 错误.当此错误传播到 WebLogic S ...

  9. Oracle PL/SQL 游标

    在PL/SQL块中执行SELECT.INSERT.DELETE和UPDATE语句时,ORACLE会在内存中为其分配上下文区(Context Area),即缓冲区.游标是指向该区的一个指针,或是命名一个 ...

  10. Oracle中的游标的原理和使用详解

    游标的简介 逐行处理查询结果,以编程的方式访问数据. 游标的类型: 1,隐式游标:在 PL/SQL 程序中执行DML SQL 语句时自动创建隐式游标,名字固定叫sql. 2,显式游标:显式游标用于处理 ...

随机推荐

  1. How to Get SharePoint Client Context in SharePoint Apps (Provider Hosted / SharePoint Access ) in CSOM (Client Side Object Model)

    http://www.codeproject.com/Articles/581060/HowplustoplusGetplusSharePointplusClientplusContex Downlo ...

  2. [Android]Android Debug key 的制作

    Android Debug key 的制作 背景 在Android App 开发过程中,我们经常会使用一些第三方的服务,但是很多的第三方服务都会要求我们提供包名,签名安装包,这时候,我们在日常调试时, ...

  3. iOS 界面调试利器Reveal

    Reveal下载地址:http://revealapp.com/ ,目前要收费了,而且还不便宜,好东西都这样嘛~ 针对越狱设备和非越狱设备可以采取不同的方法,一种是在工程项目中加入Reveal.fra ...

  4. iOS网络-02-数据解析(JSON与XML)

    数据交互格式 服务器返回给用户的数据,通常是以下两种方式: JSON XML JSON 一种轻量级的数据数据格式,体积比XML小,是服务器返回给移动端通常采用的格式 用使用JSON文件中的数据,需要对 ...

  5. [转]android访问网络:java.net.ConnectException: localhost/127.0.0.1:8888 - Connection refused

    这对刚学会向tomcat模拟的本地服务器发送请求的同学非常重要! 转自:http://wing123.iteye.com/blog/1873763 描述:在做注册功能的时候,向本地服务器:127.0. ...

  6. Android地图开发之地图的选择

    做lbs开发差不多快2年了,地图相关的产品也差不多做了3个了,用到过的地图包括google地图.高德地图.百度地图.图吧.Osmdroid,今天总结下,方便大家开发时选择合适的地图. 首先说定位模块选 ...

  7. Effective Java 47 Know and use the libraries

    Advantages of use the libraries By using a standard library, you take advantage of the knowledge of ...

  8. .net串口通信

    背景: 前一段时间需要写一个向蓝牙模块发消息的功能. 对蓝牙的机制不太了解,所以一直在查资料, 但始终没找到我需要的东西,还误以为需要配套的一套开发模板和开发包, 偶然间发现只需要简单的串口通信,并且 ...

  9. 学习随笔—Redis常用命令

    info 服务器基本信息 monitor 实时转储收到的请求 flushdb 清空当前数据库 flushall 清空所有数据库 quit 关闭连接 save 将数据同步保持到磁盘 bgsave     ...

  10. 《SQL Server企业级平台管理实践》读书笔记——SQL Server中收缩数据库不好用的原因

    数据库管理员有时候需要控制文件的大小,可能选择收缩文件,或者把某些数据文件情况以便从数据库里删除. 这时候我们就要使用到DBCC SHRINKFILE命令,此命令的脚本为: DBCC SHRINKFI ...