01_数据分析_修改当中的


/**
  工本费数据分析32列大表只用。
*/
create or replace procedure pro_basic_data (swjg in varchar2,reqTyp in varchar2 , p_CURSOR out  sys_refcursor) as
    vv_str_exeSql varchar2(3800);
    vv_plan      varchar2(3800);
    vv_prnt      varchar2(3800);
    vv_put       varchar2(3800);
    vv_store     varchar2(3800);
    vv_plan_e    varchar2(1000);
    vv_prnt_e    varchar2(1000);
    vv_temp_str   varchar2(1000);
    str           varchar2(2000);
    vv_sql        varchar2(2000);
    vv_reqTyp     varchar2(2);
    vv_swjg_lvl   varchar2(2);
    swjgdm        varchar2(10);
    zg_swjgdm     varchar2(10);
begin
    vv_reqTyp :=reqTyp ;
    swjgdm :=swjg ;
    vv_swjg_lvl :='3' ;
    zg_swjgdm:='2220102' ;
   
    IF vv_reqTyp = '0' THEN --计划
   
                  vv_plan :='select plan.plantype INVTYPE ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy'')) PREYEARTHISYEAR, ceil(to_char(his.createtime,''mm'')/3) JD, to_number(to_char(his.createtime ,''mm'')) MONTN ,sum(item.sl) sl
                            from wfhistory his  ,wfstep stp, invplan plan,invplanitem item ,(select distinct(planitem)itemid ,fpdm from invoice) ivo
                            where item.invplan = plan.bsoid and plan.plankind =0 and plan.isvalidate =1 and item.isvalidate =1
                              and item.bsoid =ivo.itemid
                              and his.objid =item.bsoid  and his.isvalidate =1
                              and his.wfstep = stp.bsoid
                              and sign(to_char(his.createtime,''yyyy'')-to_char(sysdate,''yyyy'')) <=0
                              and stp.stepname =''plan_pg'' ' ;  
                IF vv_swjg_lvl=3 THEN
                     vv_plan:= vv_plan ||' ' || 'and item.swjgdm =' ||swjgdm ;
                ELSIF  vv_swjg_lvl=2 THEN
                     vv_plan:= vv_plan ||' ' ||'and item.swjgdm like ''' || substr(swjgdm ,1,5) ||'%''';
                END IF;
                vv_plan_e:=' group by plan.plantype  ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy''))  , ceil(to_char(his.createtime,''MM'')/3) ,to_char(his.createtime ,''mm'')';
                vv_str_exeSql := vv_plan || vv_plan_e ;
  
   ELSIF vv_reqTyp = '1' THEN--印制
  
             vv_prnt :=' select  ivo.type  INVTYPE ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy'')) PREYEARTHISYEAR, ceil(to_char(his.createtime,''MM'')/3) JD,
                                  to_number(to_char(his.createtime ,''mm'')) MONTN ,sum(ivo.sl) sl
                        from wfhistory his ,wfstep stp ,invoice ivo
                        where his.objid =ivo.bsoid   and his.wfstep =stp.bsoid';
             vv_temp_str :=' ';
            
             IF vv_swjg_lvl=1 THEN
                  vv_temp_str:= '   and stp.stepname =''inv_yz''  ';
             ELSIF vv_swjg_lvl=2 THEN
                  vv_temp_str:= '   and stp.stepname =''inv_pzzxck''  and his.trg_dept like ''' || substr(swjgdm ,1,5) ||'%''';
             ELSIF  vv_swjg_lvl=3 THEN
                  vv_prnt :='select  ivo.type  INVTYPE ,to_char(sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy''))) PREYEARTHISYEAR, ceil(to_char(his.createtime,''MM'')/3) JD,
                            to_number(to_char(his.createtime ,''MM'')) MONTN ,sum(ivo.sl) sl
                            from wfhistory his ,wfstep stp ,invoice ivo
                            where his.objid =ivo.bsoid
                              and his.wfstep =stp.bsoid
                              and stp.stepname =''inv_sjck'' 
                              and his.trg_dept =' ||swjgdm || 
                            ' group by  ivo.type   ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy'')) ,
                                      ceil(to_char(his.createtime,''MM'')/3) ,to_number(to_char(his.createtime ,''MM'')) 
                      union all
                                select ''1''  INVTYPE , substr( fpdm ,6,2)  PREYEARTHISYEAR,ceil(to_char(fprk.RUSJ,''MM'')/3) JD,
                                       to_number(to_char(fprk.RUSJ ,''MM'')) MONTN ,sum(fprk.sl) sl
                                from v_fp_fprk fprk
                                where fprk.db_bj=''1''
                                  and fprk.RUSJ is not null
                                  and fprk.jsjg like '''||zg_swjgdm || '%'''||
                                ' group by  ''1''  ,substr( fpdm ,6,2) ,ceil(to_char(fprk.RUSJ,''MM'')/3) , to_number(to_char(fprk.RUSJ ,''MM''))  
                       union all
                              select ''1''  INVTYPE ,substr( fpdm ,6,2) PREYEARTHISYEAR,
                                     ceil(to_char(fprk.RUSJ,''MM'')/3) JD,
                                     to_number(to_char(fprk.RUSJ ,''mm'')) MONTN ,sum(fprk.sl) sl
                              from v_fp_fprk_dkfp fprk
                              where fprk.db_bj=''1''
                                and fprk.RUSJ is not null
                                and fprk.jsjg like '''||zg_swjgdm || '%'''||
                              ' group by  ''1''  ,substr( fpdm ,6,2) ,ceil(to_char(fprk.RUSJ,''MM'')/3) ,to_number(to_char(fprk.RUSJ ,''mm''))  ';    

             END IF;
            
             IF vv_swjg_lvl !=3 THEN
                   vv_prnt_e:=' group by  ivo.type   ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy'')) ,
                                ceil(to_char(his.createtime,''MM'')/3) ,to_number(to_char(his.createtime ,''mm''))  ';
                   vv_prnt:= vv_prnt ||vv_temp_str|| vv_prnt_e;
              END IF;
              vv_str_exeSql := vv_prnt ;
   ELSIF vv_reqTyp = '2' THEN--调拨
    
             IF vv_swjg_lvl=1 THEN
                  vv_put :='select  ivo.type  INVTYPE ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy'')) PREYEARTHISYEAR, ceil(to_char(his.createtime,''MM'')/3) JD,
                                to_number(to_char(his.createtime ,''mm'')) MONTN ,sum(ivo.sl) sl
                            from wfhistory his ,wfstep stp ,invoice ivo
                            where his.objid =ivo.bsoid
                              and his.wfstep =stp.bsoid
                              and stp.stepname =''inv_pzzxck''       
                            group by  ivo.type   ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy'')) ,
                               ceil(to_char(his.createtime,''MM'')/3) ,to_number(to_char(his.createtime ,''mm''))  ';
             ELSIF vv_swjg_lvl=2 THEN
                vv_put :='select to_char(ivo.type) INVTYPE, sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                          ceil(to_char(his.createtime, ''MM'') / 3) JD, to_number(to_char(his.createtime, ''mm'')) MONTN,  sum(ivo.sl) sl
                         from wfhistory his, wfstep stp, invoice ivo, yw_swjg_level lvl 
                         where his.objid = ivo.bsoid   and his.wfstep = stp.bsoid  and stp.stepname = ''inv_sjck''
                         and his.src_dept =' ||swjgdm ||  'and his.src_dept = lvl.swjgdm 
                         group by ivo.type, sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')),
                           ceil(to_char(his.createtime, ''MM'') / 3),   to_number(to_char(his.createtime, ''mm''))                   
                     union all
                          select ''1'' INVTYPE, sign(substr(fprk.fpdm, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                          ceil(to_char(fprk.RUSJ, ''MM'') / 3) JD,to_number(to_char(fprk.RUSJ, ''mm'')) MONTN,
                          sum(fprk.sl) sl  from v_fp_fprk fprk
                          where fprk.db_bj = ''1''  and fprk.RUSJ is not null and fprk.dbjg like  '''||zg_swjgdm || '%'''||
                          ' group by ''1'',  sign(substr(fprk.fpdm, 6, 2) - to_char(sysdate, ''yy'')),
                          ceil(to_char(fprk.RUSJ, ''MM'') / 3), to_number(to_char(fprk.RUSJ, ''mm''))     '||'
                     union all
                        select ''1'' INVTYPE, sign(substr(fprk.fpdm, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                               ceil(to_char(fprk.RUSJ, ''MM'') / 3) JD,  to_number(to_char(fprk.RUSJ, ''mm'')) MONTN, sum(fprk.sl) sl
                        from v_fp_fprk_dkfp fprk   where fprk.db_bj = ''1''  and fprk.RUSJ is not null  
                        and fprk.dbjg like  '''||zg_swjgdm || '%'''||'     
                       group by ''1'', sign(substr(fprk.fpdm, 6, 2) - to_char(sysdate, ''yy'')), ceil(to_char(fprk.RUSJ, ''MM'') / 3),to_number(to_char(fprk.RUSJ, ''mm''))' ;                                              
            ELSE
                vv_put :='select ivo.type INVTYPE,sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,   
                           ceil(to_char(his.createtime, ''MM'') / 3) JD, to_number(to_char(his.createtime, ''mm'')) MONTN,
                           sum(ivo.sl) sl  from wfhistory his, wfstep stp, invoice ivo
                           where his.objid = ivo.bsoid and his.wfstep = stp.bsoid
                           and stp.stepname = ''inv_yxs'' 
                           and his.src_dept = ' ||swjgdm ||'         
                           group by ivo.type,sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')),
                           ceil(to_char(his.createtime, ''MM'') / 3),to_number(to_char(his.createtime, ''mm''))'||
                      'union all select ''1'' INVTYPE,sign(substr(fs.fppc, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                                 ceil(to_char(fs.xs_rq, ''MM'') / 3) JD,  to_number(to_char(fs.xs_rq, ''mm'')) MONTN,       sum(fs.sl) sl
                                 from v_fp_fpfs fs  where fs.tp_sj is null  and fs.zf_bj is null
                                 group by ''1'',  sign(substr(fs.fppc, 6, 2) - to_char(sysdate, ''yy'')), ceil(to_char(fs.xs_rq, ''MM'') / 3),          to_number(to_char(fs.xs_rq, ''mm'')) ';       
            END IF;
            vv_str_exeSql := vv_put ;    
  ELSIF vv_reqTyp = '3' THEN-- 库存  
              IF vv_swjg_lvl=1 THEN    
                    vv_store :='select  ivo.type  INVTYPE ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy''))  PREYEARTHISYEAR, ceil(to_char(his.createtime,''MM'')/3) JD,
                                                  to_number(to_char(his.createtime ,''mm'')) MONTN ,sum(ivo.sl) sl
                              from wfhistory his ,wfstep stp ,invoice ivo
                              where his.objid =ivo.bsoid
                                and his.wfstep =stp.bsoid
                                and stp.stepname =''inv_pzzxkc''       
                              group by  ivo.type   ,sign( substr( ivo.fpdm ,6,2)-to_char(sysdate,''yy''))  ,
                                 ceil(to_char(his.createtime,''MM'')/3) ,to_number(to_char(his.createtime ,''mm''))  '; 
                ELSIF vv_swjg_lvl=2 THEN
                     vv_store :='select ivo.type INVTYPE,sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                                        ceil(to_char(his.createtime, ''MM'') / 3) JD,to_number(to_char(his.createtime, ''mm'')) MONTN,sum(ivo.sl) sl               
                                 from wfhistory his, wfstep stp, invoice ivo
                                 where his.objid = ivo.bsoid  and his.wfstep = stp.bsoid   and stp.stepname = ''inv_sjkc''
                                  and his.trg_dept=' ||swjgdm ||'  
                                  group by ivo.type, sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')),
                                   ceil(to_char(his.createtime, ''MM'') / 3),to_number(to_char(his.createtime, ''mm''))                                         
                            union all  ' ||
                                  'select ''1'' INVTYPE,sign(substr(kc.fppc, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                                          ceil(to_char(kc.LR_SJ, ''MM'') / 3) JD,   to_number(to_char(kc.LR_SJ, ''mm'')) MONTN,  sum(kc.sl) sl
                                   from v_fp_fpkc kc     where kc.swjg_dm  like  '''||zg_swjgdm || '%'''||'  
                                   group by ''1'',  sign(substr(kc.fppc, 6, 2) - to_char(sysdate, ''yy'')),  
                                    ceil(to_char(kc.LR_SJ, ''MM'') / 3), to_number(to_char(kc.LR_SJ, ''mm''))';                                   
                ELSE
                     vv_store :='select ivo.type INVTYPE,sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                                      ceil(to_char(his.createtime, ''MM'') / 3) JD,to_number(to_char(his.createtime, ''mm'')) MONTN,sum(ivo.sl) sl               
                               from wfhistory his, wfstep stp, invoice ivo
                               where his.objid = ivo.bsoid  and his.wfstep = stp.bsoid   and stp.stepname = ''inv_fjkc''
                                and his.trg_dept=' ||swjgdm ||'  
                                group by ivo.type, sign(substr(ivo.fpdm, 6, 2) - to_char(sysdate, ''yy'')),
                                 ceil(to_char(his.createtime, ''MM'') / 3),to_number(to_char(his.createtime, ''mm''))                                         
                          union all  ' ||
                                'select ''1'' INVTYPE,sign(substr(kc.fppc, 6, 2) - to_char(sysdate, ''yy'')) PREYEARTHISYEAR,
                                        ceil(to_char(kc.LR_SJ, ''MM'') / 3) JD,   to_number(to_char(kc.LR_SJ, ''mm'')) MONTN,  sum(kc.sl) sl
                                 from v_fp_fpkc kc     where kc.swjg_dm  like  '''||zg_swjgdm || '%'''||'  
                                 group by ''1'',  sign(substr(kc.fppc, 6, 2) - to_char(sysdate, ''yy'')),  
                                  ceil(to_char(kc.LR_SJ, ''MM'') / 3), to_number(to_char(kc.LR_SJ, ''mm''))';  
                END IF ;
                 vv_str_exeSql := vv_store ; 
   END IF;
     
  execute immediate 'insert into test_basic ('|| vv_str_exeSql ||')';
  commit;       
   vv_sql:='select ceil(nvl(w1.mon,w2.mon)/3)nQuat,nvl(w1.mon,w2.mon)mon, nvl(w1.ty_yq_sl,0) tyyq, nvl(w1.ty_bn_sl,0)  tyjn, nvl(w2.gm_yq_sl,0) gmyq, nvl(w2.gm_bn_sl,0) gmjn
          from
              (select nvl(t1.sl,0) ty_yq_sl ,nvl(t2.sl,0) ty_bn_sl , nvl(t1.montn,t2.montn ) mon
              from (select  montn ,sl from test_basic  where invtype =0   and preyearthisyear =-1) t1 full join
                    (select montn ,sl from test_basic where  invtype =0 and preyearthisyear =0 ) t2
                   on t1.montn = t2.montn ) w1 full join
              (select nvl(t1.sl,0) gm_yq_sl,nvl(t2.sl,0) gm_bn_sl, nvl(t1.montn,t2.montn ) mon
              from (select  montn ,sl from test_basic  where invtype =1   and preyearthisyear =-1) t1 full join
                    (select montn ,sl from test_basic where  invtype =1 and preyearthisyear =0 ) t2
                   on t1.montn = t2.montn ) w2  
              on  w1.mon = w2.mon';
  str:='insert into SETT_DAILYTEST ('|| vv_sql ||')';
  execute immediate str;
  commit;
  open p_CURSOR for select * from SETT_DAILYTEST;   
end pro_basic_data;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM