惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
J
Java Code Geeks
小众软件
小众软件
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
量子位
M
MIT News - Artificial intelligence
Last Week in AI
Last Week in AI
L
LangChain Blog

博客园 - ringwang

【转】 软件需求分析的工作步骤和流程 【转】软件需求分析方法 大网站安全防护措施解读【转】 互联网金融安全1【转】 python环境下载地址 批处理脚本学习 自动复制部署 苹果系统里面部署ASP.NET 23种设计模式的基本介绍 .NET MVC控制器分离到类库的方法 MYSQL临时表创建索引 【转】MySQL 性能优化的最佳20多条经验分享 【转】ASP.NET MVC IOC 之AutoFac攻略 【转】WCF与Web API 区别(应用场景) windows系统命令服务安装卸载 Mysql字段操作—增加字段、删除字段、修改字段名、修改字段类型(约束条件) 【转】 使用lftp传输文件的shell脚本 java读取文件批量插入记录 linux vmstat 系统结果说明
Oracle异常处理,动态游标
ringwang · 2014-06-12 · via 博客园 - ringwang

小例子,方便以后查阅.

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:= -1;
        --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;