【Oracle】truncate分区表
分区表是⽣产中常⽤的⼀种表,它可以实现数据的按类存放,极⼤的提⾼了数据的查询及维护。当我们不需要某⼀分区的数据时,可以采⽤truncate来清空分区。实验如下:
SQL>create table t_partition_range(id number,name varchar2(50))
2 partition by range(id)(
3 partition t_range_p1 values less than (10),
4 partition t_range_p2 values less than (20),
5 partition t_range_p3 values less than (30),
6 partition t_range_pmax values less than (maxvalue)
7 );
Table created.
SQL> col PARTITION_NAME for a20;
truncate的数据如何恢复SQL> col HIGH_VALUE for a10;
SQL>select PARTITION_NAME,HIGH_VALUE from user_tab_partitions where table_name='T_PARTITION_RANGE';
PARTITION_NAME HIGH_VALUE
-------------------- ----------
T_RANGE_P1 10
T_RANGE_P2 20
T_RANGE_P3 30
T_RANGE_PMAX MAXVALUE
SQL>insert into t_partition_range values (1,'zhangsan');
1 row created.
SQL>insert into t_partition_range values (2,'lisi');
1 row created.
SQL>insert into t_partition_range values (3,'wangwu');
1 row created.
SQL>commit;
Commit complete.
SQL>select*from t_partition_range partition (t_range_p1);
ID NAME
---------- --------------------------------------------------
1 zhangsan
2 lisi
3 wangwu
SQL>alter table t_partition_range truncate partition t_range_p1 update indexes;
Table truncated.
SQL>select*from t_partition_range partition (t_range_p1);
no rows selected
The End!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论