简体   繁体   中英

Oracle 12c - how to partition existing table?

Is it possible to partition existing table in Oracle without creating secondary table?

Or is recommended to create a second table first with all partitions and then copy over everything from a first table?

I have table 't1':

CREATE TABLE t1 (
    id INT NOT NULL,
    accountnumber VARCHAR NOT NULL,
    yr_qtr INT NOT NULL
)

yr_qtr has 15 distinct values.

I want to partition table 't1' based on yr_qtr which is int (or create 't2' with yr_qtr partitions).

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';

Output:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM