栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Oracle 11g中,如何将分区表从一个表空间移动到另一个表空间?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Oracle 11g中,如何将分区表从一个表空间移动到另一个表空间?

您还必须考虑可能使索引无效的索引,以解决有关重置默认表空间的问题,我认为这是您要实现的完整过程:

1)移动分区(根据zbrrigschn盲zlets的回答进行PL / SQL循环)

这些是我在定义a_tname,a_destTS,vTname和vTspName的匿名块包装程序中使用的过程-它们应为您提供大致的概念:

procedure mvTabPart (a_tname in varchar2, a_destTS in varchar2) iscursor pCur(vTname varchar2, vTspName varchar2) is  select table_name, partition_name  from user_tab_partitions  where table_name = vTname      and tablespace_name not like vTspName  order by partition_position desc;beginfor pRow in pCur(a_tname, a_destTS) loop sqlStmnt := 'alter table '||pRow.table_name||  ' move partition '||pRow.partition_name||  ' tablespace '||a_destTS;execute immediate sqlStmnt;end loop;end mvTabPart;

2)设置表默认分区表空间,以便在那里创建新分区:

    procedure setDefTabPart (a_tname in varchar2, a_destTS in varchar2) is    cursor tCur(vTname varchar2) is      select table_name      from user_part_tables      where table_name = vTname;    begin    for tRow in tCur(a_tname) loop     sqlStmnt := 'alter table '||tRow.table_name||      ' modify default attributes '||      ' tablespace '||a_destTS;    execute immediate sqlStmnt;    end loop;end setDefNdxPart;

3)设置索引默认分区表空间,以便在需要的位置创建新的索引分区(如果有):

procedure setDefNdxPart (a_tname in varchar2, a_destTS in varchar2) iscursor iCur(vTname varchar2) is  select index_name  from user_part_indexes  where index_name in (select index_name  from user_indexes where table_name = vTname);beginfor iRow in iCur(a_tname) loop sqlStmnt := 'alter index '||iRow.index_name||  ' modify default attributes '||  ' tablespace '||a_destTS;execute immediate sqlStmnt;end loop;end setDefNdxPart;

4)重建需要重建并且不在所需表空间中的所有分区索引:

procedure mvNdxPart (a_tname in varchar2, a_destTS in varchar2) iscursor ndxCur(vTname varchar2, vTspName varchar2) isselect i.index_name index_name, ip.partition_name partition_name  from user_ind_partitions ip, user_indexes i  where i.index_name = ip.index_name     and i.table_name = vTname     and i.partitioned = 'YES'     and (ip.tablespace_name not like vTspName or ip.status not like 'USABLE')  order by index_name, partition_name ;beginfor ndxRow in ndxCur(a_tname, a_destTS) loop sqlStmnt := 'alter index '||ndxRow.index_name||  ' rebuild partition '||ndxRow.partition_name||  ' tablespace '||a_destTS;execute immediate sqlStmnt ;end loop;end mvNdxPart;

5)重建任何全局索引

procedure mvNdx (a_tname in varchar2, a_destTS in varchar2) iscursor ndxCur(vTname varchar2, vTspName varchar2) is  select index_name  from user_indexes  where table_name = vTname       and partitioned = 'NO'       and (tablespace_name not like vTspName or status like 'UNUSABLE')  order by index_name ;beginfor ndxRow in ndxCur(a_tname, a_destTS) loop sqlStmnt := 'alter index '||ndxRow.index_name||  ' rebuild tablespace '||a_destTS;execute immediate sqlStmnt ;end loop;end mvNdx;


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/400258.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号