set unused的用法(ORACLE删除字段)

一、问题

现场有一张大数据量的分区表,数据量在10G以上。因某种原因需要删除其中的某些字段。如果直接用
alter table1 drop (column1,column2);
或者alter table1 drop column column1;和alter table1 drop column column2; 
的话,需要执行很长时间,这期间该表被锁,会影响到其它应用。

二、解决方法

使用set unused,等系统空闲时再drop unused。

1.

alter table table1 set unused (column1,column2);
或者
alter table table1 set unused column column1;
alter table table2 set unused column column2;

2.

alter table drop unused columns checkpoint 1000;

三、知识点(set unused的用法)

原理:清楚掉字典信息(撤消存储空间),不可恢复。

可以使用 SET UNUSED 选项标记一列或者多列不可用。
使用DROP SET UNUSED 选项删除被标记为不可用的列。

语法:

ALTER TABLE table SET UNUSED (COLlist多个) 或者 ALTER TABLE table SET UNUSED COLUMN col单个;

ALTER TABLE table DROP UNUSED COLUMNS [checkpoint 1000];

set unused不会真地删除字段。

除了alter table drop field外,也可以
alter table set unused field;
alter table drop unused;

set unused系统开销比较小,速度较快,所以可以先set unused,然后在系统负载较小时,再drop。如系统负载不大,也可以直接drop。

不管用何种方法,都不会收回空间。

如果你有这个需求,要删除某一个表上的某些列,但是由于这个表拥有非常大量的资料,如果你在尖峰时间直接执行 ALTER TABLE ABC DROP(COLUMN);可能会收到
ORA-01562 - failed to extend rollback segment number string,
这是因为在这个删除列的过程中你可能会消耗光整个RBS,造成这样的错误出现,因此这样的做法并不是一个好方法,就算你拼命的加大RBS空间来应付这个问题,也不会是个好主意。

我的建议做法:

1>
CREATE TABLE T1 (A NUMBER,B NUMBER);

SQL> begin
2 for i in 1 …… 100000
3 loop
4 insert into t1 values (i,100);
5 end loop;
6 commit;
7 end;

SQL> select count(*) from t1;

set unused的用法(ORACLE删除字段)的更多相关文章

  1. ORACLE删除字段(set unused的用法)

    一.问题 现场有一张大数据量的分区表,数据量在10G以上.因某种原因需要删除其中的某些字段.如果直接用 alter table1 drop (column1,column2); 或者alter tab ...

  2. oracle删除字段中的空格、回车及指定字符

    create or replace procedure PROC_test is --Description:删除字段中的指定字符(回车chr(13).换行chr(10)) --By LiChao - ...

  3. oracle删除字段时候判断字段是否存在

    declare v_count number; begin ) into v_count from all_tab_columns a where a.TABLE_NAME = 'XXX1' and ...

  4. oracle 删除字段中空格

    update  sales_report set region =  REGEXP_REPLACE(region,  '( ){1,}', '')

  5. Oracle 增加修改删除字段

    Oracle 增加修改删除字段 添加字段的语法:alter table tablename add (column datatype [default value][null/not null],…. ...

  6. oracle删除表字段和oracle表增加字段

    这篇文章主要介绍了oracle表增加字段.删除表字段修改表字段的使用方法,大家参考使用吧   添加字段的语法:alter table tablename add (column datatype [d ...

  7. Oracle SET UNUSED的用法

    SET UNUSED的用法 原理:清楚掉字典信息(撤消存储空间),不可恢复.    可以使用 SET UNUSED选项标记一列或者多列不可用.    使用DROP SET UNUSED选项删除被被标记 ...

  8. Oracle删除修改字段

    Oracle 增加修改删除字段 添加字段的语法:alter table tablename add (column datatype [default value][null/not null],…. ...

  9. Oracle 增加修改删除字段与添加注释

    添加字段的语法:alter table tablename add (column datatype [default value][null/not null],….); 修改字段的语法:alter ...

随机推荐

  1. tomcat中配置https请求

    一.  创建tomcat证书 这里使用JDK自带的keytool工具来生成证书: 1. 在jdk的安装目录\bin\keytool.exe下打开keytool.exe 2. 在命令行中输入以下命令: ...

  2. Jenkins参数化构建(二)之 Maven command line使用Jenkins参数

    安装Extened Choice Parameter插件 General模块选择‘参数化构建过程’   3. maven command line中使用 clean test -DsuiteXmlFi ...

  3. Java 数据库篇

    一.简易封装JDBC工具类: package com.jackie.MyBatis.main; import java.sql.Connection; import java.sql.DriverMa ...

  4. js实现可视化区域内拖拽

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  5. Codeforces 729E Subordinates

    题目链接:http://codeforces.com/problemset/problem/729/E 既然每一个人都有一个顶头上司,考虑一个问题: 如果这些人中具有上司数目最多的人有$x$个上司,那 ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys time limit per test2 seconds 二分

    D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. Educational Codeforces Round 23 C. Really Big Numbers 暴力

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. Spring boot @Scheduled(cron = "* * * * * *") cron表达式详解

    //@Scheduled(cron = "0 0/15 * * * ?") //每15分钟触发一次 //@Scheduled(cron = "5/10 * * * * ? ...

  9. NYOJ 1277Decimal integer conversion (第九届河南省省赛)

    XiaoMing likes mathematics, and heis just learning how to convert numbers between different bases , ...

  10. Pycharm设置去除显示的波浪线

    1.选择文件选择file—Settings,如下图打开setting对话框 2.选择Editur—Color Scheme—General选项,然后选择右边对话框中的Errors and Warnin ...