oracle 交换,移动列的位置

要求:
     移动一个分区表中的两个列的位置:
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;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值