`
wahaha603
  • 浏览: 79391 次
  • 来自: 上海
社区版块
存档分类
最新评论

oracle pl/sql 存储过程编写

阅读更多
create or replace package p_kfgl_bbtj is

  -- Author  : liucp
  -- Created : 2012/7/2 10:01:28
  -- Purpose : 
  
  --统计查询
  procedure usp_bbtj(as_s_action    in varchar2, -- 查询名目: 1=日报,2=周报,3=月报,4=员工服务,5=分点
                         as_s_cate     in varchar2, --查询类别
                         as_s_begindate      in varchar2, --开始时间
                         as_s_enddate      in varchar2, --结束时间     
                         as_s_year     in varchar2,  --查询年份   
                         as_s_staff    in varchar2, --查询员工
                         as_s_zone     in varchar2, --查询地区
                         as_s_userid     in varchar2, --执行人id
                         as_s_result      out varchar2, --返回的统计结果            
                         as_s_errorcode out varchar2,
                         as_s_errortext out varchar2);
end p_kfgl_bbtj;

 

create or replace package body p_kfgl_bbtj is

  --统计查询
procedure usp_bbtj(as_s_action    in varchar2, -- 查询名目: 1=日报,2=周报,3=月报,4=员工服务,5=分点
                         as_s_cate     in varchar2, --查询类别
                         as_s_begindate      in varchar2, --开始时间
                         as_s_enddate      in varchar2, --结束时间     
                         as_s_year     in varchar2,  --查询年份   
                         as_s_staff    in varchar2, --查询员工
                         as_s_zone     in varchar2, --查询地区
                          as_s_userid     in varchar2, --执行人id
                         as_s_result      out varchar2, --返回的统计结果            
                         as_s_errorcode out varchar2,
                         as_s_errortext out varchar2)
is
    v_s_cate     varchar(20);      
    v_s_begindate     date;   
    v_s_enddate     date;  
    v_s_year     date;   
    v_s_staff     varchar(20);   
    v_s_zone     varchar(20);     
    
    v_s_zd1       varchar(20);
    v_s_zd2       varchar(20);
    v_s_zd3       varchar(20);
    v_s_zd4       varchar(20);
    v_s_zd5       varchar(20);
    v_s_zd6       varchar(20);
    v_s_zd7       varchar(20);
    v_s_zd8       varchar(20);
    v_s_zd9       varchar(20);
    v_s_zd10       varchar(20);
    v_s_zd11      varchar(20);
    v_s_zd12       varchar(20);
    v_s_zd13       varchar(20);
    v_s_zd14       varchar(20);
    v_s_zd15       varchar(20);
    v_s_id           number(15);
    v_s_result      varchar2(500);
     v_s_sql       varchar2(500); --查询条件拼接
     v_s_sql2       varchar2(500);--统计SQL
     v_s_sql3       varchar2(500);
     v_s_sql4       varchar2(500);
     v_s_sql5       varchar2(500);
     
begin        
    as_s_errorcode := '0';
    as_s_errortext := to_char(sysdate, 'YYYY-MM-DD');
    as_s_result :='1';
    -- 数据校验
    /**
    if(as_s_cate is null) then
     as_s_errorcode := '101';
      as_s_errortext := '统计类别不能为空';
      return;
    end if;
     if(as_s_begindate is null) then
     as_s_errorcode := '102';
      as_s_errortext := '查询开始日期不能为空';
      return;
    end if;
      if(as_s_enddate is null) then
     as_s_errorcode := '103';
      as_s_errortext := '查询结束日期不能为空';
      return;
    end if;
       if(as_s_year is null) then
     as_s_errorcode := '104';
      as_s_errortext := '查询年份不能为空';
      return;
    end if;
    **/
    -- 清理之前数据
   delete  from temp_stb   where zd14 = as_s_userid;
    --日报统计
      if(as_s_action ='1') then
            -- 类别为空时默认为按服务方式 :上门 热线 大厅等等来分
                    if(as_s_cate is  not null) then 
                           v_s_sql := '  and t.service_mode =''' || as_s_cate || '''' ;          
                     end if;       
                      if(as_s_zone is not null) then 
                          v_s_sql := ' and  t.userid in (select userid from app_user app where app.zone= ''' || as_s_zone || ''')' ||v_s_sql;
                          v_s_sql4 := ' and  t.userid in (select userid from app_user app where app.zone= ''' || as_s_zone || ''')' ||v_s_sql;
                    end if;
            
                   if(as_s_cate is not null) then                
                             for i in  ( select  to_char(min_date + rownum -1,'yyyy-mm-dd')  start_time from (
  select to_date(''||as_s_begindate ||'','yyyy-mm-dd') min_date,to_date(''||as_s_enddate ||'','yyyy-mm-dd') max_date from dual        )
   connect by rownum<= max_date-min_date+1)   loop
                              v_s_zd1 := i.start_time;
                              v_s_sql3 :=  ' and to_char(t.start_time,''yyyy-mm-dd'') ='''||i.start_time||  '''' ||v_s_sql ;
                               v_s_sql5 :=  ' and to_char(t.start_time,''yyyy-mm-dd'') ='''||i.start_time||  '''' ||v_s_sql4 ;
                              v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''数字证书''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                               v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''网上申报''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                               v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''网上开票''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''应急开票''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                               v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''网购发票''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd6; 
                               v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''涉税申请''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd7; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''业务政策''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd8; 
                               v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''在线咨询''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd9; 
                               v_s_sql2  := 'select count(1) from service_info  t where   t.service_kind=''其它类''  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd10; 
                              v_s_sql2  := 'select count(1) from service_info  t where  1=1  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd11;  -- 小计
                               v_s_sql2  := 'select count(1) from service_info  t where  1=1  '  ||  v_s_sql5 ;
                              Execute Immediate v_s_sql2  into v_s_zd12;  -- 总计。。。
                               v_s_zd14 :=as_s_userid;
                           
                              select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd6,
                                                zd7,
                                                zd8,
                                                zd9,
                                                zd10,
                                                zd11,
                                                zd12,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd6,
                                                v_s_zd7,
                                                v_s_zd8,
                                                v_s_zd9,
                                                v_s_zd10,
                                                v_s_zd11,
                                                v_s_zd12,
                                                 v_s_zd14
                                                 );
                              
                           end loop;
                     end if;        
      end if;
   
     
    
    --月报统计
    if(as_s_action ='3') then
            -- 类别为空时默认为按服务方式 :上门 热线 大厅等等来分
                    if(as_s_zone is not null) then 
                          v_s_sql := ' and  t.userid in (select userid from app_user app where app.zone= ''' || as_s_zone || ''')';
                    end if;
                     if(as_s_year is  null) then 
                          as_s_errorcode := '301';
                          as_s_errortext := '查询年份不能为空';
                          return;
                    end if;
                   if(as_s_cate is null) then
                           for i in  (select  d.itemvalue as service_type  from dictionary d where d.itemname='服务类(别)型')   loop
                              v_s_zd1 := i.service_type;
                              v_s_sql3 := 'and t.service_mode ='''|| v_s_zd1 ||''' ' || v_s_sql ;
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-01'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-02'' ) '  || v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-03'' ) '  || v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-04'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-05'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd6; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-06'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd7; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-07'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd8; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-08'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd9; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-09'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd10; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-10'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd11; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-11'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd12; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-12'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd13; 
                              v_s_zd14 :=as_s_userid;
                              select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd6,
                                                zd7,
                                                zd8,
                                                zd9,
                                                zd10,
                                                zd11,
                                                zd12,
                                                zd13,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd6,
                                                v_s_zd7,
                                                v_s_zd8,
                                                v_s_zd9,
                                                v_s_zd10,
                                                v_s_zd11,
                                                v_s_zd12,
                                                v_s_zd13,
                                                 v_s_zd14
                                           );
                              
                           end loop;
                   else
                             for i in  (select  d.itemvalue as service_type  from dictionary d where d.itemname='服务类别')   loop
                              v_s_zd1 := i.service_type;
                              v_s_sql3 := 'and t.service_kind ='''|| v_s_zd1 ||''' '  || v_s_sql ;
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-01'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-02'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-03'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-04'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-05'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd6; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-06'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd7; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-07'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd8; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-08'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd9; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-09'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd10; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-10'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd11; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-11'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd12; 
                              v_s_sql2  := 'select count(1) from service_info  t where   (to_char(t.start_time,''yyyy-mm'')='''||  as_s_year ||'-12'' ) '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd13; 
                               v_s_zd14 :=as_s_userid;
                              select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd6,
                                                zd7,
                                                zd8,
                                                zd9,
                                                zd10,
                                                zd11,
                                                zd12,
                                                zd13,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd6,
                                                v_s_zd7,
                                                v_s_zd8,
                                                v_s_zd9,
                                                v_s_zd10,
                                                v_s_zd11,
                                                v_s_zd12,
                                                v_s_zd13,
                                                v_s_zd14
                                           );
                              
                           end loop;
                     end if;        
      end if;
   
    --员工服务方式统计  
    if(as_s_action ='4') then
             if(as_s_zone is not null) then  
                         v_s_sql := ' and  t.userid in (select userid from app_user app where app.zone= ''' || as_s_zone || ''')';
              end if;
             if(as_s_begindate is  not null) then 
                       v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')>=''' || as_s_begindate || '''' ||v_s_sql ;          
            end if;       
            if(as_s_enddate is  not null) then 
                       v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')<=''' || as_s_enddate || ''''  ||v_s_sql;          
            end if;   
            
            if(as_s_zone is not null) then  
                        for i in  (select fullname, userid  from app_user app where  app.depid='1' and app.status='1' and app.zone='' || as_s_zone || '')   loop
                              v_s_zd1 := i.fullname;
                              v_s_sql3 := 'and t.userid ='''|| i.userid ||''' '  ||v_s_sql;
                              v_s_sql2  := 'select count(1) from service_info  t where 1=1'  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''热线'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''大厅'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                               v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''上门'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''自助办税机'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd6; 
                               v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''在线咨询'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd7; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''大厅辅助服务'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd8; 
                               v_s_zd14 :=as_s_userid;
                               select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd6,
                                                zd7,
                                                zd8,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd6,
                                                v_s_zd7,
                                                v_s_zd8,
                                                v_s_zd14
                                           );                          
                        end loop;
                  else
                            for i in  (select fullname, userid  from app_user app where app.depid='1' and app.status='1')   loop
                              v_s_zd1 := i.fullname;
                              v_s_sql3 := 'and t.userid ='''|| i.userid ||''' '  ||v_s_sql;
                              v_s_sql2  := 'select count(1) from service_info  t where 1=1 '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''热线'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''大厅'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                               v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''上门'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''自助办税机'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd6; 
                               v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''在线咨询'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd7; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''大厅辅助服务'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd8; 
                               v_s_zd14 :=as_s_userid;
                               select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd6,
                                                zd7,
                                                zd8,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd6,
                                                v_s_zd7,
                                                v_s_zd8,
                                                 v_s_zd14
                                           );                          
                        end loop;
             end if;
            
    end if;
     
     --分点(周)日报统计
       if(as_s_action ='5') then
            -- 类别为空时默认为按服务方式 :上门 热线 大厅等等来分
                    if(as_s_begindate is  not null) then 
                           v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')>=''' || as_s_begindate || '''' ||v_s_sql ;          
                     end if;       
                     if(as_s_enddate is  not null) then 
                            v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')<=''' || as_s_enddate || ''''  ||v_s_sql;          
                     end if;   
            
                   if(as_s_cate is null) then
                           for i in  (select  d.itemvalue as service_type  from dictionary d where d.itemname='服务类(别)型')   loop
                              v_s_zd1 := i.service_type;
                              v_s_sql3 := 'and t.service_mode ='''|| v_s_zd1 ||''' ' || v_s_sql ;
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''昆山'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''张家港'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''常熟'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''太仓'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''园区'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd6; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''吴中'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd7; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''市局'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd8; 
                              v_s_sql2  := 'select count(1) from service_info  t where  1=1  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd9; 
                              v_s_zd14 :=as_s_userid;
                              select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd6,
                                                zd7,
                                                zd8,
                                                zd9,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd6,
                                                v_s_zd7,
                                                v_s_zd8,
                                                v_s_zd9,
                                                v_s_zd14
                                           );
                              
                           end loop;
                   else
                             for i in  (select  d.itemvalue as service_type  from dictionary d where d.itemname='服务类别')   loop
                              v_s_zd1 := i.service_type;
                              v_s_sql3 := 'and t.service_kind ='''|| v_s_zd1 ||''' '  || v_s_sql ;
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''昆山'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''张家港'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''常熟'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''太仓'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''园区'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd6; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''吴中'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd7; 
                              v_s_sql2  := 'select count(1) from service_info  t where   t.userid in (select userid from app_user app where app.zone=''市局'')  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd8; 
                              v_s_sql2  := 'select count(1) from service_info  t where  1=1  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd9; 
                                v_s_zd14 :=as_s_userid;
                              select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd6,
                                                zd7,
                                                zd8,
                                                zd9,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd6,
                                                v_s_zd7,
                                                v_s_zd8,
                                                v_s_zd9,
                                                v_s_zd14
                                           );
                              
                           end loop;
                     end if;        
      end if;
      
    -- 首页推送 (服务类型服务量统计 上门 热线 大厅。。占比等)
        if(as_s_action ='6') then
            -- 默认当前时间为查询条件
                    if(as_s_begindate is null and as_s_enddate is  null ) then
                           v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'') = to_char(sysdate,''yyyy-MM-dd'')' ;        
                           else 
                                 if(as_s_begindate is  not null) then 
                                                     v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')>=''' || as_s_begindate || '''' ||v_s_sql ;          
                                  end if;       
                                  if(as_s_enddate is  not null) then 
                                           v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')<=''' || as_s_enddate || ''''  ||v_s_sql;          
                                  end if;   
                    end if;
                  if(as_s_zone is not null) then  
                         v_s_sql := ' and  t.userid in (select userid from app_user app where app.zone= ''' || as_s_zone || ''')';
                  end if;
            
                   if(as_s_cate is not null) then
                           for i in  (select  d.itemvalue as service_type  from dictionary d where d.itemname='服务类(别)型')   loop
                              v_s_zd1 := i.service_type;
                              v_s_sql3 := 'and t.service_mode ='''|| v_s_zd1 ||''' ' || v_s_sql ;
                              v_s_sql2  := 'select count(1) from service_info  t where   1=1  '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              
                              v_s_sql2  := 'select count(1) from service_info  t where  1=1  '  ||  v_s_sql ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                          --    v_s_zd3 :=(v_s_zd2/(v_s_zd3+0.0000001));
                                v_s_sql2  :=  'SELECT ROUND('''||v_s_zd2||''' /('''||v_s_zd3||'''+0.000001), 3) * 100 || ''%'' FROM DUAL';
                             Execute Immediate v_s_sql2  into v_s_zd3; 
                              select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd14
                                           );
                              
                           end loop;
                end if;        
      end if;
    
   --首页推送 (主要类别服务量统计 网上开票.数字证书 占比等)
   
    if(as_s_action ='7') then
           -- 默认当前时间为查询条件
                    if(as_s_begindate is null and as_s_enddate is  null ) then
                           v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'') = to_char(sysdate,''yyyy-MM-dd'')' ;        
                           else 
                                 if(as_s_begindate is  not null) then 
                                                     v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')>=''' || as_s_begindate || '''' ||v_s_sql ;          
                                  end if;       
                                  if(as_s_enddate is  not null) then 
                                           v_s_sql := '  and to_char(t.start_time,''yyyy-MM-dd'')<=''' || as_s_enddate || ''''  ||v_s_sql;          
                                  end if;   
                    end if;
                  if(as_s_zone is not null) then  
                         v_s_sql := ' and  t.userid in (select userid from app_user app where app.zone= ''' || as_s_zone || ''')';
                  end if;
            
            if(as_s_zone is not null) then  
                        for i in (select  d.itemvalue as service_type  from dictionary d where d.itemname='服务类别')  loop
                              v_s_zd1 := i.service_type;
                              v_s_sql3 := 'and t.service_kind ='''|| v_s_zd1 ||''' ' || v_s_sql ;
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''热线''' ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd2; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''大厅'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd3; 
                              v_s_sql2  := 'select count(1) from service_info  t  where t.service_mode =''上门'''  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd4; 
                               v_s_sql2  := 'select count(1) from service_info  t  where 1=1 '  ||  v_s_sql3 ;
                              Execute Immediate v_s_sql2  into v_s_zd5; 
                               v_s_zd14 :=as_s_userid;
                               select S_TEMP_STB.NEXTVAL into v_s_id from dual;
                              insert into temp_stb (id,
                                                 zd1,
                                                zd2,
                                                zd3,
                                                zd4,
                                                zd5,
                                                zd14)
                                           values (v_s_id,
                                                 v_s_zd1,
                                                v_s_zd2,
                                                v_s_zd3,
                                                v_s_zd4,
                                                v_s_zd5,
                                                v_s_zd14
                                           );                          
                        end loop;
              end if;
            
    end if;  
     --异常捕捉
  Exception
    When others then
      as_s_errorcode := sqlcode;
      as_s_errortext := sqlerrm;
      RollBack;
 
end;
 

end p_kfgl_bbtj;

 

分享到:
评论
2 楼 wahaha603 2012-07-12  
datawarehouse 写道
缺了好几个建表语句。

写给自己看的 就看个结构 呵呵
1 楼 datawarehouse 2012-07-09  
缺了好几个建表语句。

相关推荐

    Oracle PL/SQL实战(待续)

    Oracle PL/SQL是一种强大的编程语言,它结合了SQL的数据处理能力与PL的程序设计特性,是Oracle数据库系统中用于创建存储过程、函数、触发器和包的主要工具。在这个"Oracle PL/SQL实战(待续)"的主题中,我们将深入...

    oracle pl/sql从入门到精通 配套源代码

    Oracle PL/SQL是一种强大的编程语言,它结合了SQL(结构化查询语言)的数据库操作功能与PL/SQL的程序设计特性,广泛应用于Oracle数据库的开发和管理。这本书"Oracle PL/SQL从入门到精通"的配套源代码,显然是为了...

    Oracle PL/SQL实例精解 数据库建立代码

    除了基本的数据库对象创建,PL/SQL还允许我们编写存储过程、函数、触发器等,以实现更复杂的业务逻辑。例如,我们可以创建一个存储过程来处理学生选课: ```sql CREATE OR REPLACE PROCEDURE enroll_student( p_...

    ORACLE PL/SQL从入门到精通

    ORACLE PL/SQL是从入门到精通的专业知识,涵盖了数据库开发与管理的多个方面,包括触发器、过程、函数、软件包、异常处理、游标、循环、分支、变量使用、数据库安装等关键知识点。 触发器是数据库中用来保证数据...

    Oracle PL/SQL程序设计(第5版)(上下册)

    - **PL/SQL简介**:PL/SQL(Procedural Language for SQL)是Oracle数据库的一种内嵌式过程化语言,用于增强SQL的功能。它允许在SQL查询的基础上添加控制流语句、变量定义、错误处理等特性。 - **环境搭建与配置**:...

    Oracle PL/SQL 实例精解(第4版涵盖Oracle 11g)+源码脚本

    PL/SQL是Oracle数据库中用于创建存储过程、函数、触发器、包等数据库对象的主要工具。第4版特别关注了在Oracle 11g环境下的新特性,如性能优化、错误处理和并发控制等。 1. **基础语法**:PL/SQL的基础包括声明变量...

    oracle10g_pl/sql

    Oracle 10g PL/SQL 是Oracle数据库系统中用于创建和管理存储过程、函数、触发器等数据库对象的编程语言。本教程旨在为初学者提供一个全面的学习平台,同时也为经验丰富的开发者提供参考资料。PL/SQL是Oracle特有的...

    Oracle PL/SQL专家指南-高级PL/SQL解决方案的设计与开发

    PL/SQL是Oracle数据库特有的编程语言,它结合了SQL的查询能力与过程式编程语言的功能,使得数据库管理、数据处理和业务逻辑实现更为高效。本书针对那些希望提升PL/SQL编程技能,设计和开发复杂数据库解决方案的...

    Oracle PL/SQL学习官方教材

    Oracle PL/SQL是一种强大的编程语言,它将SQL与过程编程语言的特性相结合,为数据库开发提供了丰富的功能。在Oracle数据库环境中,PL/SQL是开发高效、可靠和可维护的数据库应用程序的关键工具。以下是对"Oracle PL/...

    oracle 9i pl/sql程序设计笔记

    ### Oracle 9i PL/SQL程序设计笔记精要 #### PL/SQL基础知识概览 **标题与描述**:本文档围绕“Oracle 9i PL/SQL程序设计笔记”这一核心主题,深入探讨了PL/SQL语言的基础知识及其在Oracle 9i数据库环境中的应用。...

    Oracle PL/SQL programming(5th Edition)

    ### Oracle PL/SQL Programming知识点概览 #### 一、书籍基本信息 - **书名**:Oracle PL/SQL Programming(第五版) - **作者**:Steven Feuerstein 和 Bill Pribyl - **出版日期**:2009年10月1日 - **出版社**:...

    Oracle PL/SQL by Example(4th Edition)

    《Oracle PL/SQL by Example(4th Edition)》是一本专为Oracle数据库用户设计的PL/SQL编程指南,尤其适合那些希望通过实践学习这一强大的过程式语言的开发者。本书的第四版详细介绍了Oracle PL/SQL的各种核心概念和...

    《精通Oracle PL/SQL》源码

    Oracle PL/SQL是一种强大的编程语言,它结合了SQL(结构化查询语言)的数据库操作能力和PL(过程化语言)的程序设计特性,是Oracle数据库系统中的核心组件之一。《精通Oracle PL/SQL》这本书深入探讨了这个语言的...

    Oracle PL/SQL语言初级教程

    总之,Oracle PL/SQL语言初级教程将引导初学者逐步掌握PL/SQL的基础知识,包括语法、数据类型、函数、表和视图的管理、完整性约束、过程和函数、操作控制以及异常处理。通过学习,开发者可以编写出高效、稳定的...

    oracle_oracle_oraclepl/sql_

    1. **PL/SQL简介**:PL/SQL是Oracle数据库的内置编程语言,用于创建存储过程、函数、触发器和包。它的语法基于SQL,但增加了流程控制、异常处理和数据类型等特性。 2. **变量和数据类型**:PL/SQL支持多种数据类型...

    oracle pl/sql最佳实践

    Oracle PL/SQL是一种强大的编程语言,它结合了SQL的数据库操作能力和Procedural Language的控制结构,使得数据库管理员和开发人员能够创建复杂的数据处理逻辑和应用程序。本篇将深入探讨Oracle PL/SQL的最佳实践,...

    Oracle PL/SQL程序设计(第5版)示例代码

    首先,PL/SQL是Oracle数据库支持的一种过程化编程语言,结合了SQL查询和控制结构,用于创建复杂的数据处理逻辑。它包括声明变量、条件判断、循环控制、异常处理等多个组成部分,使得开发者能够编写出高效且健壮的...

    oracle pl/sql fundamentals

    PL/SQL是Oracle数据库特有的结构化查询语言扩展,它结合了SQL的强大功能与过程性编程语言的特点,使得开发者能够编写复杂的业务逻辑和数据库操作。 在本教程中,学生将学习以下核心知识点: 1. **PL/SQL概述**:...

    oracle pl sql 实例精解 源代码

    最后,ChapterExampleScripts.zip可能包含的是各章的示例脚本,这些脚本可能涵盖了从基础的SQL查询到复杂的事务处理、存储过程的编写、数据库连接池的使用等多个方面。通过阅读和执行这些脚本,读者能掌握如何在PL/...

Global site tag (gtag.js) - Google Analytics