是否可以在不创建辅助表的情况下对Oracle中的现有表进行分区?
或者建议首先使用所有分区创建第二个表,然后从第一个表复制所有内容?
我有桌子't1':
CREATE TABLE t1 (
id INT NOT NULL,
accountnumber VARCHAR NOT NULL,
yr_qtr INT NOT NULL
)
yr_qtr有15个不同的值。
我想根据yr_qtr(即int)创建表't1'(或使用yr_qtr分区创建't2')。
答案 0 :(得分:0)
drop table t1;
CREATE TABLE t1 (
id INT NOT NULL,
accountnumber VARCHAR2(2) NOT NULL,
yr_qtr INT NOT NULL
);
insert all
into t1 values(1,'AB',20141)
into t1 values(2,'CD',20142)
into t1 values(3,'EF',20143)
into t1 values(4,'GH',20144)
into t1 values(5,'IJ',20145)
select * from dual;
select * from user_tab_partitions where table_name = 'T1';
select * from t1;
--Creating Partition online
ALTER TABLE t1
MODIFY PARTITION BY RANGE (yr_qtr)
INTERVAL (1) ( PARTITION P1 VALUES LESS THAN (20141) ) ONLINE;
select * from t1;
select * from user_tab_partitions where table_name = 'T1';
输出:
Table dropped.
Table created.
5 row(s) inserted.
no data found
Result Set 5
ID ACCOUNTNUMBER YR_QTR
1 AB 20141
2 CD 20142
3 EF 20143
4 GH 20144
5 IJ 20145
Download CSV
5 rows selected.
Table altered.
Result Set 6
ID ACCOUNTNUMBER YR_QTR
1 AB 20141
2 CD 20142
3 EF 20143
4 GH 20144
5 IJ 20145
Download CSV
5 rows selected.
Result Set 7
TABLE_NAME COMPOSITE PARTITION_NAME SUBPARTITION_COUNT HIGH_VALUE HIGH_VALUE_LENGTH PARTITION_POSITION TABLESPACE_NAME PCT_FREE PCT_USED INI_TRANS MAX_TRANS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENT MAX_EXTENT MAX_SIZE PCT_INCREASE FREELISTS FREELIST_GROUPS LOGGING COMPRESSION COMPRESS_FOR NUM_ROWS BLOCKS EMPTY_BLOCKS AVG_SPACE CHAIN_CNT AVG_ROW_LEN SAMPLE_SIZE LAST_ANALYZED BUFFER_POOL FLASH_CACHE CELL_FLASH_CACHE GLOBAL_STATS USER_STATS IS_NESTED PARENT_TABLE_PARTITION INTERVAL SEGMENT_CREATED INDEXING READ_ONLY INMEMORY INMEMORY_PRIORITY INMEMORY_DISTRIBUTE INMEMORY_COMPRESSION INMEMORY_DUPLICATE CELLMEMORY INMEMORY_SERVICE INMEMORY_SERVICE_NAME
T1 NO P1 0 20141 5 1 LIVESQL_USERS 10 - 1 255 65536 1048576 1 2147483645 2147483645 - - - YES DISABLED - - - - - - - - - DEFAULT DEFAULT DEFAULT NO NO NO - NO YES ON NO DISABLED - - - - - - -
T1 NO SYS_P29017 0 20142 5 2 LIVESQL_USERS 10 - 1 255 65536 1048576 1 2147483645 2147483645 - - - YES DISABLED - - - - - - - - - DEFAULT DEFAULT DEFAULT NO NO NO - YES YES ON NO DISABLED - - - - - - -
T1 NO SYS_P29018 0 20143 5 3 LIVESQL_USERS 10 - 1 255 65536 1048576 1 2147483645 2147483645 - - - YES DISABLED - - - - - - - - - DEFAULT DEFAULT DEFAULT NO NO NO - YES YES ON NO DISABLED - - - - - - -
T1 NO SYS_P29019 0 20144 5 4 LIVESQL_USERS 10 - 1 255 65536 1048576 1 2147483645 2147483645 - - - YES DISABLED - - - - - - - - - DEFAULT DEFAULT DEFAULT NO NO NO - YES YES ON NO DISABLED - - - - - - -
T1 NO SYS_P29020 0 20145 5 5 LIVESQL_USERS 10 - 1 255 65536 1048576 1 2147483645 2147483645 - - - YES DISABLED - - - - - - - - - DEFAULT DEFAULT DEFAULT NO NO NO - YES YES ON NO DISABLED - - - - - - -
T1 NO SYS_P29021 0 20146 5 6 LIVESQL_USERS 10 - 1 255 65536 1048576 1 2147483645 2147483645 - - - YES DISABLED - - - - - - - - - DEFAULT DEFAULT DEFAULT NO NO NO - YES YES ON NO DISABLED - - - - - - -
Download CSV
6 rows selected.