要求:
移动一个分区表中的两个列的位置:
desc tbln_testA;
BRCD NOT NULL CHAR(4)
DSBSID NOT NULL CHAR(3)
CNCLDT CHAR(8)
USRIDCNCLOP VARCHAR2(10)
USRIDCNCLMNGR VARCHAR2(10)
交换USRIDCNCLOP 和 USRIDCNCLMNGR 位置,修改为:
desc tbln_testA;
BRCD NOT NULL CHAR(4)
DSBSID NOT NULL CHAR(3)
CNCLDT CHAR(8)
USRIDCNCLMNGR VARCHAR2(10)
USRIDCNCLOP VARCHAR2(10)
对 tbln_testA 进行分析:
1. 上面有一个物化视图
2. 上面一个主键索引
3. 有三个分区
4. 有一个同义词
5. 一个public 查询权限
6. select count(*) from tbln_testA;
移动过程
0.
1. 创建临时表
create table ln1.tbln_testA_TEMP
partition by range (BRCD)
(
partition PT_5006 values less than ('5007')
tablespace TS_5006
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
),
partition PT_5201 values less than ('5202')
tablespace TS_5201
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
),
partition PT_5921 values less than ('5922')
tablespace TS_5921
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
)
)
as
select BRCD,DSBSID,CNCLDT ,USRIDCNCLMNGR,USRIDCNCLOP from ln1.tbln_testA;
2. 验证临时表中的数据 select count(*) from tbln_testA_TEMP; 与select count(*) from ln1.tbln_testA; 数据一致
3. 删除原表
drop ln1.tbln_testA
4. 重新创建表
create table ln1.tbln_testA
partition by range (BRCD)
(
partition PT_5006 values less than ('5007')
tablespace TS_5006
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
),
partition PT_5201 values less than ('5202')
tablespace TS_5201
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
),
partition PT_5921 values less than ('5922')
tablespace TS_5921
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
)
)
as select * from tbln_testA_TEMP;
5. 创建主键索引
6. 赋予public 查询权限
7. 创建synonym
8. 创建物化视图
9. 检查 tbln_testA 相应的信息,确保正常, 查询dba_object 查询无效对象
10. 删除bln_testA_TEMP
==========================
如果表不是分区表可以这样做:
1. create table tb_A_TEMP as select 正确的列的序列 from tb_A;
2. alter table tb_A rename to tb_A _bak;
3.alter table tb_A_TEMP rename to tb_A;
4. 验证结果,ok后可以drop tb_A _bak;