转移LOB字段的表空间

--部署时若要导入的表空间名称和开发机上的不一致,而你的表中有LOB字段,那头就大了。--能治好这种头大症的代码如下:

create or replace procedure volumeChangeTableAndIndex
(
tablespacename in varchar2
)
as
cursor tablecur is select table_name from user_all_tables;
cursor indexcur is select index_name,tablespace_name from user_indexes order by index_name;
cursor lobtables is select table_name,column_name from user_tab_cols t where t.data_type like '%LOB%';
begin
--修改当前用户所有表的表空
for tablesname in tablecur loop
execute immediate 'alter table '||tablesname.table_name ||' move tablespace '||tablespacename;
end loop;

--修改当前用户所有Lob字段的表空间
for lobtable in lobtables loop
execute immediate 'ALTER TABLE '||lobtable.table_name||' MOVE LOB('||lobtable.column_name||') STORE AS(TABLESPACE '||tablespacename||')';
end loop;

--重建索引
for indexsname in indexcur loop
if indexsname.tablespace_name <> Upper(tablespacename) then
dbms_output.put_line(indexsname.index_name);
execute immediate 'alter index '||indexsname.index_name ||' rebuild tablespace '||tablespacename;
end if;
end loop;
end;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值