存储过程实例

下面这段存储过程实现的逻辑:

统计昨天注册的新用户的数据,插入到指定的表中,提供给应用程序查询,生成报表。

 

 

CREATE OR REPLACE PROCEDURE agent_reguser_static
-- 统计昨天的用户注册信息:                                                                       
                                                                                          
is                                                                                                                           
ls_user_id number(10);                                                                                              
ls_remarks varchar2(10);                                                                                                    
ls_websiteid varchar2(15);
ls_salesid varchar2(150);  
ls_agentid varchar2(15);                                                                                                                           
                                                                                                                             
begin
 delete from agent_reg_user where to_char(time,'yyyy-mm-dd') = to_char( sysdate-1,'yyyy-mm-dd' );--删除掉历史数据,重新统计
 commit;
 
 declare  cursor cur_reg_user is    --统计昨天新注册的用户   
  select distinct w.userid,w.sitevalue from web_listen w,agent_user_info a where to_char(w.regdate,'yyyy-mm-dd')
   =to_char( sysdate-1,'yyyy-mm-dd') and ((w.sitevalue = a.agentid and a.agentlevel = 3) or (w.sitevalue like 'lerss%'));
    
 begin
  open cur_reg_user;
        loop
         fetch cur_reg_user into ls_user_id, ls_websiteid;
         exit when cur_reg_user%notfound;


  if substr(ls_websiteid,1,5) ='lerss' then
   ls_salesid := '080829005000001';
   ls_agentid := '080829005';
  else  
   select agentid,parentid into ls_salesid,ls_agentid from agent_user_info where agentid in( select parentid from agent_user_info
    where agentid = ls_websiteid and agentlevel = 3);
  end if;
    
  --将注册信息插入到表agent_reg_user中
  insert into agent_reg_user(id,userid,username,truename,cardnum,mobile,email,area,time,websiteid,salesid,agentid)
 
  select SEQ_AGENT_REG_USER.nextval,ls_user_id,username,truename,cardid,phone,email,substr(cardid,1,2)||'0000',
   time,ls_websiteid,ls_salesid,ls_agentid from luser where id = ls_user_id;
  commit;

 end loop ;
 close cur_reg_user;                                                                                               
    
  --更新area信息,如果不属于基本省的地区信息,则均属于其它
  update agent_reg_user set area = '100000' where to_char(time,'yyyy-mm-dd') = to_char( sysdate-1,'yyyy-mm-dd' )
   and area not in  (select area_id from agent_area_dic);
  commit;
end;
                                                                                                                         
end agent_reguser_static;
/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值