CREATE TABLE sales_by_region
(dept_number NUMBER NOT NULL,
dept_name VARCHAR2(20),
quarterly_sales NUMBER(10,2),
state VARCHAR2(2)
)
PARTITION BY LIST (state)
(
PARTITION yearly_north VALUES ('MN','WI','MI'),
PARTITION yearly_south VALUES ('NM','TX','GA'),
PARTITION yearly_east VALUES ('MA','NY','NC'),
PARTITION yearly_west VALUES ('CA','OR','WA'),
PARTITION unknown VALUES (DEFAULT)
)
Table created.
SELECT PARTITION_NAME, HIGH_VALUE FROM USER_TAB_PARTITIONS WHERE TABLE_NAME ='SALES_BY_REGION'
PARTITION_NAME | HIGH_VALUE | UNKNOWN | DEFAULT | YEARLY_EAST | 'MA', 'NY', 'NC' | YEARLY_NORTH | 'MN', 'WI', 'MI' | YEARLY_SOUTH | 'NM', 'TX', 'GA' | YEARLY_WEST | 'CA', 'OR', 'WA' |
---|
INSERT INTO SALES_BY_REGION VALUES (002, 'AUTO NORTH', 450000, 'MN')
1 row(s) inserted.
INSERT INTO SALES_BY_REGION VALUES (004, 'AUTO SOUTH', 945000, 'GA')
1 row(s) inserted.
INSERT INTO SALES_BY_REGION VALUES (006, 'AUTO EAST', 2125000, 'MA')
1 row(s) inserted.
INSERT INTO SALES_BY_REGION VALUES (006, 'AUTO EAST', 6101000, 'NY')
1 row(s) inserted.
INSERT INTO SALES_BY_REGION VALUES (006, 'AUTO EAST', 741000, 'NC')
1 row(s) inserted.
INSERT INTO SALES_BY_REGION VALUES (008, 'AUTO WEST', 901000, 'OR')
1 row(s) inserted.
INSERT INTO SALES_BY_REGION VALUES (009, 'AUTO MIDWEST', 1950000, 'AZ')
1 row(s) inserted.
INSERT INTO SALES_BY_REGION VALUES (009, 'AUTO MIDWEST', 5725000, 'UT')
1 row(s) inserted.
SELECT DEPT_NUMBER, DEPT_NAME, QUARTERLY_SALES, STATE FROM SALES_BY_REGION PARTITION(yearly_east)
DEPT_NUMBER | DEPT_NAME | QUARTERLY_SALES | STATE | 6 | AUTO EAST | 2125000 | MA | 6 | AUTO EAST | 6101000 | NY | 6 | AUTO EAST | 741000 | NC |
---|
SELECT DEPT_NUMBER, DEPT_NAME, QUARTERLY_SALES, STATE FROM SALES_BY_REGION PARTITION(unknown)
DEPT_NUMBER | DEPT_NAME | QUARTERLY_SALES | STATE | 9 | AUTO MIDWEST | 1950000 | AZ | 9 | AUTO MIDWEST | 5725000 | UT |
---|
ALTER TABLE sales_by_region ADD PARTITION yearly_midwest VALUES ('AZ', 'UT')
ORA-14323: cannot add partition when DEFAULT partition existsMore Details: https://docs.oracle.com/error-help/db/ora-14323
ALTER TABLE sales_by_region
SPLIT PARTITION unknown VALUES ('AZ', 'UT')
INTO
( PARTITION yearly_midwest,
PARTITION unknown)
Table altered.
SELECT PARTITION_NAME, HIGH_VALUE FROM USER_TAB_PARTITIONS WHERE TABLE_NAME ='SALES_BY_REGION'
PARTITION_NAME | HIGH_VALUE | UNKNOWN | DEFAULT | YEARLY_EAST | 'MA', 'NY', 'NC' | YEARLY_MIDWEST | 'AZ', 'UT' | YEARLY_NORTH | 'MN', 'WI', 'MI' | YEARLY_SOUTH | 'NM', 'TX', 'GA' | YEARLY_WEST | 'CA', 'OR', 'WA' |
---|
SELECT DEPT_NUMBER, DEPT_NAME, QUARTERLY_SALES, STATE FROM SALES_BY_REGION PARTITION(yearly_midwest)
DEPT_NUMBER | DEPT_NAME | QUARTERLY_SALES | STATE | 9 | AUTO MIDWEST | 1950000 | AZ | 9 | AUTO MIDWEST | 5725000 | UT |
---|
SELECT DEPT_NUMBER, DEPT_NAME, QUARTERLY_SALES, STATE FROM SALES_BY_REGION PARTITION(unknown)
no data found