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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
T
Tenable Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
W
WeLiveSecurity
D
DataBreaches.Net
Attack and Defense Labs
Attack and Defense Labs
H
Heimdal Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
AI
AI
P
Proofpoint News Feed
PCI Perspectives
PCI Perspectives
Schneier on Security
Schneier on Security
T
Threatpost
GbyAI
GbyAI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
F
Full Disclosure
T
Threat Research - Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
M
MIT News - Artificial intelligence
L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
Y
Y Combinator Blog
腾讯CDC
The Hacker News
The Hacker News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园_首页
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 最新话题
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
SegmentFault 最新的问题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LangChain Blog
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
量子位
P
Proofpoint News Feed
H
Hacker News: Front Page
Help Net Security
Help Net Security
L
LINUX DO - 热门话题
Project Zero
Project Zero
C
Cisco Blogs

博客园 - 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;