Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4006104
  • 博文数量: 536
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4825
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(536)

文章存档

2024年(3)

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(252)

2006年(73)

分类: Oracle

2006-11-23 15:37:58

如何将多个结构相同的普通表转换为一个分区表?

测试 Oracle Version 9.2.0.4
-----------------------------------
文件名: part.sql
/*
 from :
 */
create table t1 as
select sysdate dt, all_objects.*
from all_objects
/

create table t2 as
select add_months(sysdate, -12) dt, all_objects.*
from all_objects
/

create table t3 as
select add_months(sysdate, -24) dt, all_objects.*
from all_objects
/

create table t
(dt, owner, object_name, subobject_name, object_id,
 data_object_id, object_type, created, last_ddl_time, timestamp, status,
 temporary, generated, secondary)
 partition by range(dt)(
 partition part2004 values less than (to_date('01-jan-2005','dd-mon-yyyy')),  
 partition part2005 values less than (to_date('01-jan-2006','dd-mon-yyyy')),  
 partition part2006 values less than (to_date('01-jan-2007','dd-mon-yyyy'))  
 )
 as
 select sysdate dt, all_objects.*
 from all_objects
 where 1=0
/

alter table t
exchange partition part2006
with table t1
without validation
/

alter table t
exchange partition part2005
with table t2
without validation
/

alter table t
exchange partition part2004
with table t3
without validation
/

-----------------------------------
以下为运行结果:
SQL> @part.sql
DOC> from :
DOC> */

Table created.


Table created.


Table created.


Table created.


Table altered.


Table altered.


Table altered.

SQL> select table_name from user_tables;

TABLE_NAME                                                                      
------------------------------                                                  
T                                                                               
T1                                                                              
T2                                                                              
T3                                                                              

SQL> select count(*) from t1;

  COUNT(*)                                                                      
----------                                                                      
         0                                                                      

SQL> select count(*) from t2;

  COUNT(*)                                                                      
----------                                                                      
         0                                                                      

SQL> select count(*) from t3;

  COUNT(*)                                                                      
----------                                                                      
         0                                                                      

SQL> select count(*) from t;

  COUNT(*)                                                                      
----------                                                                      
     30162                                                                      

SQL> drop table t1;

Table dropped.

SQL> drop table t2;

Table dropped.

SQL> drop table t3;

Table dropped.

SQL> select table_name from user_tables;

TABLE_NAME                                                                      
------------------------------                                                  
T                                                                             

阅读(994) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~