数据库过程语句留档:财务数据报表显示

create or replace procedure biller533.shzc_202008_cwbb_jfbb_kshxs_mx
(p_userid varchar2,p_rq varchar2,p_qx in varchar2, p_bbxz in varchar2, 
p_xx in varchar2, p_zbsx in varchar2, p_sfdb in varchar2, 
p_cursor in out Results.ref_cursor_type)
as

v_rq              VARCHAR2(80);
v_zbpm              VARCHAR2(80);
v_sql             VARCHAR2(30000);
v_hd             VARCHAR2(100);
v_qx              VARCHAR2(10);
v_bbxz          VARCHAR2(10);

v_yyyy             VARCHAR2(10);


SQLSTMT0 VARCHAR2(32760);

begin

   v_rq := substr( p_rq,1,6);
   v_yyyy := substr( p_rq,1,4);
   v_bbxz := substr( p_bbxz,1,6);

   
     ----权限的控制 开始
  select max(qx) into v_qx from zhyw.zibo_jyfx_staff where trim(userid)=p_userid;
  select name into v_qx from zhyw.rpt_county where county_id=v_qx;
   
      zhyw.fan_drop_retable(upper('cwbb_jfbb_yyjk_ksh_bmys_jg'),'SHZC');
      SQLSTMT0 := 'create table shzc.cwbb_jfbb_yyjk_ksh_bmys_jg as
      select a.编号,a.指标名称,a.一级分类,a.二级分类,a.指标单位,a.指标属性,a.指标方向,a.责任人,a.重点指标
      from 
      (select a.编号,replace(a.指标名称,''"'','''') 指标名称,a.一级分类,a.二级分类,a.指标单位,a.指标属性,
      a.指标方向,a.责任人,a.重点指标,row_number() over (partition by a.编号  order by a.in_time desc ) 排名 
      from  shzc.cwbb_jfbb_yyjk_ksh_bmys a ) a
      where a.排名=1  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      
      
   
   ----过程---
      ----本地留存
      SQLSTMT0 := 'insert into  shzc.cwbb_jfbbdr_sjdr_mx_bd 
      select * from  shzc.cwbb_jfbbdr_sjdr_mx  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      ---指标
      SQLSTMT0 := 'insert into shzc.cwbb_zbys_sjdr_mx(编号,一级项目名称,二级项目名称,三级项目名称,in_time)
      select a.编号,a.数据1,a.数据2,a.数据3,a.in_time 
      from  shzc.cwbb_jfbbdr_sjdr_mx a where a.指标_排名_基础=''指标''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      ---排名
      SQLSTMT0 := 'insert into shzc.cwbb_qspm_sjdr_mx(指标编码,时间,区县,排名,in_time)
      select a.编号,a.数据1,a.数据2,a.数据3,a.in_time 
      from  shzc.cwbb_jfbbdr_sjdr_mx a where a.指标_排名_基础=''排名''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      ---基础
      SQLSTMT0 := 'insert into shzc.cwbb_jcsj_sjdr_mx(指标编码,时间,区县,指标值,排名,in_time)
      select a.编号,a.数据1,a.数据2,a.数据3,a.数据4,a.in_time 
      from shzc.cwbb_jfbbdr_sjdr_mx a where a.指标_排名_基础=''基础''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      ---清空经分导入表
      SQLSTMT0 := 'delete shzc.cwbb_jfbbdr_sjdr_mx  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;
      
      ---取时间最后的数据
      
      ----生成中间表
      
      SQLSTMT0 := 'update shzc.cwbb_jcsj_sjdr_mx a set a.指标值=0
      where a.指标值=''---''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;
      
      SQLSTMT0 := 'update shzc.cwbb_jcsj_sjdr_mx a set a.指标值=0
      where a.指标值=''-''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;
      
      SQLSTMT0 := 'update shzc.cwbb_jcsj_sjdr_mx a set a.指标值=0
      where a.指标值=''-0''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;
      
      SQLSTMT0 := 'update shzc.cwbb_jcsj_sjdr_mx a set a.指标值=0
      where 指标值=''#VALUE!''   ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;
      
      SQLSTMT0 := 'update shzc.cwbb_jcsj_sjdr_mx a set a.指标值=15
      where a.指标值=''ERROR 15''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;

      SQLSTMT0 := 'update shzc.cwbb_jcsj_sjdr_mx a set a.指标值=0.58
      where a.指标值=''"58%"''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;

      SQLSTMT0 := 'update shzc.cwbb_jcsj_sjdr_mx a set a.指标值=0.603
      where a.指标值=''"60.3%"''  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      commit;
      
      zhyw.fan_drop_retable(upper('cwbb_zbys_sjdr_jg'),'SHZC');
      SQLSTMT0 := 'create table shzc.cwbb_zbys_sjdr_jg as
      select a.编号,a.一级项目名称,a.二级项目名称,a.三级项目名称
      from 
      (select a.编号,a.一级项目名称,a.二级项目名称,a.三级项目名称,
      row_number() over (partition by a.编号  order by a.in_time desc,a.id desc ) 排名 
      from shzc.cwbb_zbys_sjdr_mx a ) a
      where a.排名=1  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      
      zhyw.fan_drop_retable(upper('cwbb_qspm_sjdr_jg'),'SHZC');
      SQLSTMT0 := 'create table shzc.cwbb_qspm_sjdr_jg as
      select a.指标编码,a.时间,a.区县, 排名 
      from 
      (select a.指标编码,a.时间,a.区县,nvl(a.排名,0) 排名,
      row_number() over (partition by a.指标编码,a.时间,a.区县  order by a.in_time desc,a.id desc ) 排序 
      from shzc.cwbb_qspm_sjdr_mx a ) a
      where a.排序=1  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      
      zhyw.fan_drop_retable(upper('cwbb_jcsj_sjdr_jg'),'SHZC');
      SQLSTMT0 := 'create table shzc.cwbb_jcsj_sjdr_jg as
      select a.指标编码,a.时间,a.区县, 指标值,排名 
      from 
      (select a.指标编码,a.时间,a.区县,nvl(a.指标值,0) 指标值,nvl(a.排名,0) 排名,
      row_number() over (partition by a.指标编码,a.时间,a.区县  order by a.in_time desc,a.id desc ) 排序 
      from shzc.cwbb_jcsj_sjdr_mx a ) a
      where a.排序=1  ';
      EXECUTE IMMEDIATE (SQLSTMT0);
      
      

    -------过程---
    
      zhyw.fan_drop_retable(upper('cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga'),'SHZC');
      SQLSTMT0 := 'create table shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga as
      select a.*,b.指标名称,b.一级分类,b.二级分类,b.指标单位,b.指标属性,b.指标方向,b.责任人,b.重点指标 ,
       NVL(case when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''1'' then ''10''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''2'' then ''9''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''3'' then ''8''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''4'' then ''7''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''5'' then ''6''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''6'' then ''5''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''7'' then ''4''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''8'' then ''3''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''9'' then ''2''
               when b.指标方向 =''反向'' and a.区县<>''全市'' and nvl(a.排名,''0'') =''10'' then ''1''
                 
               when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''1'' 	then ''17''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''2''	then ''16''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''3''	then ''15''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''4''	then ''14''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''5''	then ''13''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''6''	then ''12''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''7''	then ''11''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''8''	then ''10''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''9''	then ''9''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''10''	then ''8''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''11''	then ''7''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''12''	then ''6''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''13''	then ''5''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''14''	then ''4''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''15''	then ''3''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''16''	then ''2''
                when b.指标方向 =''反向'' and a.区县=''全市'' and nvl(a.排名,''0'') =''17''	then ''1'' END,A.排名) Z排名
      from  shzc.cwbb_zb_pm_jc_jg a,
       shzc.cwbb_jfbb_yyjk_ksh_bmys_jg b
       where a.时间='''||v_rq||'''
       and a.指标编码=b.编号
       and a.区县 not in (''区县'',''省均'',''市公司'')';
      EXECUTE IMMEDIATE (SQLSTMT0); 
    
    
       zhyw.fan_drop_retable(upper('cwbb_jfbb_yyjk_ksh_'||v_rq||'_jgb'),'SHZC');
       SQLSTMT0 := 'create table shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jgb as
       select a.区县,a.指标属性,
       count(distinct case when a.一级分类=''C市场'' then a.指标编码 end) C市场指标数量,
       count(distinct case when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码  end) C市场短板指标数量,
       round(count(distinct case when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 ) then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''C市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''C市场'' then a.指标编码 end)),4)*100 C市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''H市场'' then a.指标编码 end) H市场指标数量,
       count(distinct case when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) H市场短板指标数量,
       round(count(distinct case when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''H市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''H市场'' then a.指标编码 end)),4)*100 H市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''B市场'' then a.指标编码 end) B市场指标数量,
       count(distinct case when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) B市场短板指标数量,
       round(count(distinct case when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''B市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''B市场'' then a.指标编码 end)),4)*100 B市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''N市场'' then a.指标编码 end) N市场指标数量,
       count(distinct case when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) N市场短板指标数量,
       round(count(distinct case when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''N市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''N市场'' then a.指标编码 end)),4)*100 N市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''其他'' then a.指标编码 end) 其他指标数量,
       count(distinct case when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) 其他短板指标数量,
       round(count(distinct case when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''其他'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''其他'' then a.指标编码 end)),4)*100 其他短板指标占比 

       from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a 
       group by a.区县,a.指标属性
       union all
       select a.区县,''总合计'',
       count(distinct case when a.一级分类=''C市场'' then a.指标编码 end) C市场指标数量,
       count(distinct case when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码  end) C市场短板指标数量,
       round(count(distinct case when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''C市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 ) then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''C市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''C市场'' then a.指标编码 end)),4)*100 C市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''H市场'' then a.指标编码 end) H市场指标数量,
       count(distinct case when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) H市场短板指标数量,
       round(count(distinct case when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''H市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''H市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''H市场'' then a.指标编码 end)),4)*100 H市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''B市场'' then a.指标编码 end) B市场指标数量,
       count(distinct case when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) B市场短板指标数量,
       round(count(distinct case when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''B市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''B市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''B市场'' then a.指标编码 end)),4)*100 B市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''N市场'' then a.指标编码 end) N市场指标数量,
       count(distinct case when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) N市场短板指标数量,
       round(count(distinct case when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''N市场'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''N市场'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''N市场'' then a.指标编码 end)),4)*100 N市场短板指标占比 ,
        
        count(distinct case when a.一级分类=''其他'' then a.指标编码 end) 其他指标数量,
       count(distinct case when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end) 其他短板指标数量,
       round(count(distinct case when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''正向'' and  to_number(nvl(a.排名,''0'')) in (17,16,15,14,13,12 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''正向'' and to_number(nvl(a.排名,''0''))  in (10,9,8 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县 =''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0'')) in (1,2,3,4,5,6 )  then a.指标编码
                                     when a.一级分类=''其他'' and a.区县<>''全市'' and a.指标方向=''反向'' and to_number(nvl(a.排名,''0''))  in (1,2,3 )  then a.指标编码 end)/
        decode( count(distinct case when a.一级分类=''其他'' then a.指标编码 end),0,1,
        count(distinct case when a.一级分类=''其他'' then a.指标编码 end)),4)*100 其他短板指标占比 

       from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a 
       group by a.区县        ';
      EXECUTE IMMEDIATE (SQLSTMT0); 


       zhyw.fan_drop_retable(upper('cwbb_jfbb_yyjk_ksh_'||v_rq||'_jgc'),'SHZC');
       SQLSTMT0 := 'create table shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jgc as
       select a.* from 
       (select c.区县市区,c.顺序,a.区县,a.指标属性,
       a.c市场指标数量,a.C市场短板指标数量,a.C市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.C市场短板指标占比 desc ) C市场排名,
       a.H市场指标数量	,a.H市场短板指标数量	,a.H市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.H市场短板指标占比 desc ) H市场排名,
       a.B市场指标数量	,a.B市场短板指标数量	,a.B市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.B市场短板指标占比 desc ) B市场排名,
       a.N市场指标数量	,a.N市场短板指标数量	,a.N市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.N市场短板指标占比 desc ) N市场排名,
       a.其他指标数量	,a.其他短板指标数量	,a.其他短板指标占比,
       row_number() over (partition by a.指标属性 order by a.其他短板指标占比 desc ) 其他排名
       from 
       (select * from  SHZC.cwbb_bbzx_qx_pm_bm_mx c where c.区县市区=''区县'') c,
       shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jgb a
       where c.名称=a.区县
       union all
       
       
       select c.区县市区,c.顺序,a.区县,a.指标属性,
       a.c市场指标数量,a.C市场短板指标数量,a.C市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.C市场短板指标占比 desc ) C市场排名,
       a.H市场指标数量	,a.H市场短板指标数量	,a.H市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.H市场短板指标占比 desc ) H市场排名,
       a.B市场指标数量	,a.B市场短板指标数量	,a.B市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.B市场短板指标占比 desc ) B市场排名,
       a.N市场指标数量	,a.N市场短板指标数量	,a.N市场短板指标占比	,
       row_number() over (partition by a.指标属性 order by a.N市场短板指标占比 desc ) N市场排名,
       a.其他指标数量	,a.其他短板指标数量	,a.其他短板指标占比,
       row_number() over (partition by a.指标属性 order by a.其他短板指标占比 desc ) 其他排名
       from 
       (select * from  SHZC.cwbb_bbzx_qx_pm_bm_mx c where c.区县市区<>''区县'') c,
       shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jgb a
       where c.名称=a.区县 ) a
       order by a.区县市区,a.顺序,a.指标属性  ';
      EXECUTE IMMEDIATE (SQLSTMT0); 
      
      zhyw.fan_drop_retable(upper('cwbb_jfbb_yyjk_ksh_'||v_yyyy||'_jga'),'SHZC');
       SQLSTMT0 := 'create table shzc.cwbb_jfbb_yyjk_ksh_'||v_yyyy||'_jga as
      select a.*,b.指标名称,b.一级分类,b.二级分类,b.指标单位,b.指标属性,b.指标方向,b.责任人,b.重点指标,d.分析单元
      from  shzc.cwbb_zb_pm_jc_jg a,
       shzc.cwbb_jfbb_yyjk_ksh_bmys_jg b,
       shzc.cwbb_jfbb_yyjk_ksh_fcdy d
       where substr(a.时间,1,4)='''||v_yyyy||'''
       and a.指标编码=b.编号
       and a.指标编码=d.指标编码(+)
       and a.区县 not in (''区县'',''省均'',''市公司'')   ';
      EXECUTE IMMEDIATE (SQLSTMT0); 
      
       zhyw.fan_drop_retable(upper('cwbb_jfbb_yyjk_ksh_'||v_yyyy||'_jgb'),'SHZC');
       SQLSTMT0 := 'create table shzc.cwbb_jfbb_yyjk_ksh_'||v_yyyy||'_jgb as
        select a.分析单元,a.区县,a.指标编码,a.指标名称,a.一级分类,a.责任人,a.指标属性,a.指标方向,
        max(nvl(case when a.时间='''||v_yyyy||'''||''01'' 	then a.指标值 end,0)) y1指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''02''	then a.指标值 end,0)) y2指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''03''	then a.指标值 end,0)) y3指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''04''	then a.指标值 end,0)) y4指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''05''	then a.指标值 end,0)) y5指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''06''	then a.指标值 end,0)) y6指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''07''	then a.指标值 end,0)) y7指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''08''	then a.指标值 end,0)) y8指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''09''	then a.指标值 end,0)) y9指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''10''	then a.指标值 end,0)) y10指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''11''	then a.指标值 end,0)) y11指标值,
        max(nvl(case when a.时间='''||v_yyyy||'''||''12''	then a.指标值 end,0)) y12指标值
        from shzc.cwbb_jfbb_yyjk_ksh_'||v_yyyy||'_jga a
        group by a.分析单元,a.区县,a.指标编码,a.指标名称,a.一级分类,a.责任人,a.指标属性,a.指标方向  ';
      EXECUTE IMMEDIATE (SQLSTMT0); 
           
      SQLSTMT0:='delete from shzc.cwbb_jfbb_yyjk_ksh_yyyy_jgb a where a.yyyy='''||v_yyyy||'''  ' ;
      execute immediate (SQLSTMT0);
      commit;
      
      SQLSTMT0:='insert into  shzc.cwbb_jfbb_yyjk_ksh_yyyy_jgb  
      select '''||v_yyyy||''' yyyy, a.* from shzc.cwbb_jfbb_yyjk_ksh_'||v_yyyy||'_jgb a   ' ;
      execute immediate (SQLSTMT0);
      commit;
         
   
if v_bbxz='1' then ---首页
      if p_zbsx='全部' then
        if p_qx='全市' then
           v_sql:='select ''区县市区'',''顺序'',''区县'',''指标属性'',
           ''C市场指标数量'',''C市场短板指标数量'',''C市场短板指标占比'',''C市场短板指标排名'',
           ''H市场指标数量'',''H市场短板指标数量'',''H市场短板指标占比'',''H市场短板指标排名'',
           ''B市场指标数量'',''B市场短板指标数量'',''B市场短板指标占比'',''B市场短板指标排名'',
           ''N市场指标数量'',''N市场短板指标数量'',''N市场短板指标占比'',''N市场短板指标排名'',
           ''其他指标数量'',''其他短板指标数量'',''其他短板指标占比'' ,''其他短板指标排名''
           from dual union all 
           select 区县市区,to_char(顺序),区县,指标属性,
           to_char(C市场指标数量),to_char(C市场短板指标数量),to_char(C市场短板指标占比),to_char(C市场排名),
           to_char(H市场指标数量),to_char(H市场短板指标数量),to_char(H市场短板指标占比),to_char(H市场排名),
           to_char(B市场指标数量),to_char(B市场短板指标数量),to_char(B市场短板指标占比),to_char(B市场排名),
           to_char(N市场指标数量),to_char(N市场短板指标数量),to_char(N市场短板指标占比),to_char(N市场排名),
           to_char(其他指标数量),to_char(其他短板指标数量),to_char(其他短板指标占比) ,to_char(其他排名)
           from shzc.CWBB_JFBB_YYJK_KSH_'||v_rq||'_JGC b
            '       ;
            
        else
            v_sql:=' select ''区县市区'',''顺序'',''区县'',''指标属性'',
           ''C市场指标数量'',''C市场短板指标数量'',''C市场短板指标占比'',''C市场短板指标排名'',
           ''H市场指标数量'',''H市场短板指标数量'',''H市场短板指标占比'',''H市场短板指标排名'',
           ''B市场指标数量'',''B市场短板指标数量'',''B市场短板指标占比'',''B市场短板指标排名'',
           ''N市场指标数量'',''N市场短板指标数量'',''N市场短板指标占比'',''N市场短板指标排名'',
           ''其他指标数量'',''其他短板指标数量'',''其他短板指标占比'' ,''其他短板指标排名''
           from dual union all 
           select 区县市区,to_char(顺序),区县,指标属性,
           to_char(C市场指标数量),to_char(C市场短板指标数量),to_char(C市场短板指标占比),to_char(C市场排名),
           to_char(H市场指标数量),to_char(H市场短板指标数量),to_char(H市场短板指标占比),to_char(H市场排名),
           to_char(B市场指标数量),to_char(B市场短板指标数量),to_char(B市场短板指标占比),to_char(B市场排名),
           to_char(N市场指标数量),to_char(N市场短板指标数量),to_char(N市场短板指标占比),to_char(N市场排名),
           to_char(其他指标数量),to_char(其他短板指标数量),to_char(其他短板指标占比) ,to_char(其他排名)
           from shzc.CWBB_JFBB_YYJK_KSH_'||v_rq||'_JGC b
            where b.区县='''||p_qx||'''  '       ;
        end if ;
       else
          if p_qx='全市' then
           v_sql:='select ''区县市区'',''顺序'',''区县'',''指标属性'',
           ''C市场指标数量'',''C市场短板指标数量'',''C市场短板指标占比'',''C市场短板指标排名'',
           ''H市场指标数量'',''H市场短板指标数量'',''H市场短板指标占比'',''H市场短板指标排名'',
           ''B市场指标数量'',''B市场短板指标数量'',''B市场短板指标占比'',''B市场短板指标排名'',
           ''N市场指标数量'',''N市场短板指标数量'',''N市场短板指标占比'',''N市场短板指标排名'',
           ''其他指标数量'',''其他短板指标数量'',''其他短板指标占比'' ,''其他短板指标排名''
           from dual union all 
           select 区县市区,to_char(顺序),区县,指标属性,
           to_char(C市场指标数量),to_char(C市场短板指标数量),to_char(C市场短板指标占比),to_char(C市场排名),
           to_char(H市场指标数量),to_char(H市场短板指标数量),to_char(H市场短板指标占比),to_char(H市场排名),
           to_char(B市场指标数量),to_char(B市场短板指标数量),to_char(B市场短板指标占比),to_char(B市场排名),
           to_char(N市场指标数量),to_char(N市场短板指标数量),to_char(N市场短板指标占比),to_char(N市场排名),
           to_char(其他指标数量),to_char(其他短板指标数量),to_char(其他短板指标占比) ,to_char(其他排名)
           from shzc.CWBB_JFBB_YYJK_KSH_'||v_rq||'_JGC b
           where  指标属性='''||p_zbsx||''' '       ;
            
        else
            v_sql:=' select ''区县市区'',''顺序'',''区县'',''指标属性'',
           ''C市场指标数量'',''C市场短板指标数量'',''C市场短板指标占比'',''C市场短板指标排名'',
           ''H市场指标数量'',''H市场短板指标数量'',''H市场短板指标占比'',''H市场短板指标排名'',
           ''B市场指标数量'',''B市场短板指标数量'',''B市场短板指标占比'',''B市场短板指标排名'',
           ''N市场指标数量'',''N市场短板指标数量'',''N市场短板指标占比'',''N市场短板指标排名'',
           ''其他指标数量'',''其他短板指标数量'',''其他短板指标占比'' ,''其他短板指标排名''
           from dual union all 
           select 区县市区,to_char(顺序),区县,指标属性,
           to_char(C市场指标数量),to_char(C市场短板指标数量),to_char(C市场短板指标占比),to_char(C市场排名),
           to_char(H市场指标数量),to_char(H市场短板指标数量),to_char(H市场短板指标占比),to_char(H市场排名),
           to_char(B市场指标数量),to_char(B市场短板指标数量),to_char(B市场短板指标占比),to_char(B市场排名),
           to_char(N市场指标数量),to_char(N市场短板指标数量),to_char(N市场短板指标占比),to_char(N市场排名),
           to_char(其他指标数量),to_char(其他短板指标数量),to_char(其他短板指标占比) ,to_char(其他排名)
           from shzc.CWBB_JFBB_YYJK_KSH_'||v_rq||'_JGC b
            where b.区县='''||p_qx||''' 
            and 指标属性='''||p_zbsx||''' '       ;
        end if ;
     end if ;   
       
elsif v_bbxz='2' then
   if p_sfdb='全部' then
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='非短板'  then
    
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            and to_number(Z排名)<=11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='短板'  then
    
       if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            and to_number(Z排名)>11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''C市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    end if; 
    
elsif v_bbxz='3' then
     if p_sfdb='全部' then 
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='非短板'  then
    
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            and to_number(Z排名)<=11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='短板'  then
    
       if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            and to_number(Z排名)>11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''H市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    end if; 
      
 elsif v_bbxz='4' then
    if p_sfdb='全部' then 
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='非短板'  then
    
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            and to_number(Z排名)<=11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='短板'  then
    
       if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            and to_number(Z排名)>11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''B市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    end if;   
 elsif v_bbxz='5' then
   if p_sfdb='全部' then 
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
   elsif p_sfdb='非短板'  then
    
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            and to_number(Z排名)<=11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='短板'  then
    
       if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            and to_number(Z排名)>11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''N市场''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    end if; 
 elsif v_bbxz='6' then
   if p_sfdb='全部' then 
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='非短板'  then
    
      if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            and to_number(Z排名)<=11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            and to_number(Z排名)<=7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    elsif p_sfdb='短板'  then
    
       if v_qx='全市' then
        if p_qx='全市' then
           v_sql:='select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            and to_number(Z排名)>11
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        else
            v_sql:=' select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
            
        end if ;
       elsif v_qx=p_qx then
            v_sql:='  select ''指标属性'',''指标编码'',''指标名称'',''指标值'',''指标方向'',''排名''
            from dual union all 
            select a.* from 
            (select a.指标属性,a.指标编码,a.指标名称,a.指标值,a.指标方向,a.排名
            from shzc.cwbb_jfbb_yyjk_ksh_'||v_rq||'_jga a where a.区县='''||p_qx||'''
            and a.一级分类=''其他''
            and to_number(Z排名)>7
            order by to_number(Z排名) desc,a.指标编码 ) a '       ;
      end if;
    end if;   
end if;

           
  open p_cursor for v_sql;

end ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值