为含有分区及子分区的模型添加分区。

为含有分区及子分区的模型添加分区。,第1张

概述为含有分区及子分区的模型添加分区。

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

create or replace procedure p_test_gy(v_datacycle_ID varchar2,--添加分区的上限值                                      v_entity_owner varchar2,v_entity_name  varchar2,v_retcode      out varchar2,v_retinfo      out varchar2) is  v_cnt1           number; --实体检测  v_cnt2           number; --分区是否存在检测  v_cnt3           number; --模板子分区是否存在检测  v_part_type      varchar2(30); --分区类型  v_subpart_type   varchar2(30); --子分区类型  v_part_value_max varchar2(30); --分区最大值  v_part_style     varchar2(30); --分区命名格式  v_part_value     varchar2(30); --分区值变量  v_sql            varchar2(4000); --动态执行sql  v_sub_template   varchar2(4000); --调整模板子分区   v_high_value  long; --子分区值变量  v_subpart_value     varchar2(30); --子分区值变量  /*v_pkg  v_procname */begin  /*--插入日志部分  p_insert_log(v_acct_month,v_pkg,v_procname,v_prov_ID,sysdate,'');*/  --检测输入参数是否有误  select count(0)    into v_cnt1    from sys.dba_objects   where owner = v_entity_owner     and object_name = v_entity_name     and object_type = 'table';  if v_cnt1 = 0 then    v_retcode := 'FAIL';    v_retinfo := '目标表信息输入有误';  else    --检测目标表有无分区    select count(0)      into v_cnt2      from sys.dba_part_tables t     where t.owner = v_entity_owner       and t.table_name = v_entity_name;    if v_cnt2 = 0 then      v_retcode := 'SUCCESS';      v_retinfo := '目标表无分区';    else      --检测分区是否已存在      select regexp_replace(max(t.partition_name),'[^0-9]',''),regexp_replace(max(t.partition_name),'[0-9]','')        into v_part_value_max,v_part_style        from sys.dba_tab_partitions t       where t.table_owner = v_entity_owner         and t.table_name = v_entity_name;      select partitioning_type,subpartitioning_type        into v_part_type,v_subpart_type        from sys.dba_part_tables t       where t.owner = v_entity_owner         and t.table_name = v_entity_name;         --分区已存在&分区是List/HASH分区      if v_part_value_max >= v_datacycle_ID OR v_part_type <> 'RANGE' then        v_retcode := 'SUCCESS';        v_retinfo := '分区已存在';      else        select count(0)          into v_cnt3          from sys.dba_subpartition_templates         where table_name = v_entity_name           and user_name = v_entity_owner;           --无子分区&有子分区且为模板子分区        if v_part_type = 'RANGE' AND           ((v_subpart_type = 'List' AND v_cnt3 <> 0) OR           nvl(v_subpart_type,'**') = 'NONE') then          v_part_value := to_char(add_months(to_date(v_part_value_max,'yyyymm'),1),'yyyymm');          while v_part_value <= v_datacycle_ID loop            v_sql := 'alter table ' || v_entity_owner || '.' ||                     v_entity_name || ' add partition ' || v_part_style ||                     v_part_value || '   values less than (''' ||                     to_char(add_months(to_date(v_part_value,'yyyymm') || ''') tablespace ';             --日志检索                            /*dbms_output.put_line(v_sql);*/            --需要分配分区(或者建表设置默认表空间)            execute immediate v_sql;            v_part_value := to_char(add_months(to_date(v_part_value,'yyyymm');          end loop;          v_retcode := 'SUCCESS';          v_retinfo := '成功';        else          /*--顺序不太好看             select                  rtrim(wmsys.wm_concat(' subpartition ' || substr(subpartition_name,length(partition_name)+2) || ' values ( ''' ||                regexp_replace(substr(subpartition_name,length(partition_name)+2),'') || ''' ) '),',') into v_sub_template           from sys.dba_tab_subpartitions          where table_owner = v_entity_owner            and partition_name = v_part_value_max            and table_name = v_entity_name;*/            --有子分区且非模板子分区          v_sub_template := 'alter table ' || v_entity_owner || '.' ||                            v_entity_name || 'set subpartition template(';--''' ||regexp_replace(substr(subpartition_name,length(partition_name) + 2),'') || '''          for t in (select /*+parallel(sub,4)*/*                      from sys.dba_tab_subpartitions sub                     where table_owner = v_entity_owner                       and partition_name = v_part_style || v_part_value_max                       and table_name = v_entity_name                     order by length(regexp_replace(subpartition_name,'')),subpartition_name) loop          v_high_value:=t.high_value;          v_subpart_value:=substr(v_high_value,1,4000);          /*if v_subpart_value= 'DEFAulT' then             v_subpart_value:='''DEFAulT''';            end if;*/            v_sub_template := v_sub_template ||' subpartition ' ||                           substr(t.subpartition_name,length(t.partition_name) + 2) ||                           ' values ( '||v_subpart_value||' ),' ;          end loop;          --日志检索          dbms_output.put_line(rtrim(v_sub_template,') || ')');          insert into dm_check_log            select rtrim(v_sub_template,') || ')',v_datacycle_ID,sysdate              from dual;          commit;          execute immediate rtrim(v_sub_template,') || ')';          v_part_value := to_char(add_months(to_date(v_part_value_max,'yyyymm') || ''') tablespace ';            /*dbms_output.put_line(v_sql);*/          execute immediate v_sql;            --需要分配分区(或者建表设置默认表空间)            v_part_value := to_char(add_months(to_date(v_part_value,'yyyymm');          end loop;          v_retcode := 'SUCCESS';          v_retinfo := '成功';        end if;      end if;    end if;  end if;end;

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的为含有分区及子分区的模型添加分区。全部内容,希望文章能够帮你解决为含有分区及子分区的模型添加分区。所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1165083.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存