ORACLE 如何应用带子分区的 CTAS?
ORACLE HOW TO APPLY CTAS WITH SUBPARTITION?
我正在尝试使用未分区 table 的 CTAS 构建子分区 table,但出现错误。我该怎么做 that.Here 是我的数据 ID 的类似示例 IS PRIMARY KEY:
TASK
ID START_DATE
1 22/09/21
2 21/09/21
3 20/09/21
这是我的代码:
CREATE TABLE EMPLOYEE AS
(SELECT * FROM TASK)
PARTITION BY RANGE ("START_DATE")
SUBPARTITION BY LIST("ID")
PARTITION P1 VALUES LESS THAN TO_DATE('20210920','YYYYYMMDD') (
SUBPARTITION S1 VALUES (1),
SUBPARTITION S2 VALUES (2),
SUBPARTITION S3 VALUES (3)
),
PARTITION P2 VALUES LESS THAN TO_DATE('20210921','YYYYYMMDD') (
SUBPARTITION S4 VALUES (1),
SUBPARTITION S5 VALUES (2),
SUBPARTITION S6 VALUES (3)
),
PARTITION P3 VALUES LESS THAN TO_DATE('20210922','YYYYYMMDD') (
SUBPARTITION S7 VALUES (1),
SUBPARTITION S8 VALUES (2),
SUBPARTITION S9 VALUES (3)
),
PARTITION P4 VALUES LESS THAN MAXVALUE (
SUBPARTITION S10 VALUES (1),
SUBPARTITION S11 VALUES (2),
SUBPARTITION S12 VALUES (3)
)
我该怎么做,这对我来说很重要,我收到了这个错误,我想当我更正它时我会收到另一个错误:
00933. 00000 - "SQL command not properly ended"
一个例子
SQL> create table task ( id number , start_date date ) ;
Table created.
SQL> CREATE TABLE t2
2 PARTITION BY RANGE (START_DATE)
3 SUBPARTITION BY LIST (ID)
4 (
5 PARTITION P1 VALUES LESS THAN (TO_DATE('2021-07-20','YYYY-MM-DD'))
6 (
7 SUBPARTITION S1 VALUES (1),
8 SUBPARTITION S2 VALUES (2),
9 SUBPARTITION S3 VALUES (3)
10 ),
11 PARTITION P2 VALUES LESS THAN (TO_DATE('2021-08-20','YYYY-MM-DD'))
12 (
13 SUBPARTITION S4 VALUES (1),
14 SUBPARTITION S5 VALUES (2),
15 SUBPARTITION S6 VALUES (3)
16 )
17 )
18* as select * from task
SQL> /
Table created.
注意事项
- 在构造的最后使用表达式
as select * from xxx
。
- 记住每个分区和子分区构造的括号。
- 虽然我没有把它放在我的示例中,但尝试使用子分区模板。
我会推荐一个 INTERVAL
分区和子分区模板。会是这个吗:
CREATE TABLE EMPLOYEE (
...
)
PARTITION BY RANGE (START_DATE) INTERVAL (INTERVAL '1' DAY)
SUBPARTITION BY LIST (ID)
SUBPARTITION TEMPLATE (
SUBPARTITION S1 VALUES (1),
SUBPARTITION S2 VALUES (2),
SUBPARTITION S3 VALUES (3)
)
( PARTITION P_INITIAL VALUES LESS THAN (TIMESTAMP '2021-09-01 00:00:00') SEGMENT CREATION DEFERRED );
我正在尝试使用未分区 table 的 CTAS 构建子分区 table,但出现错误。我该怎么做 that.Here 是我的数据 ID 的类似示例 IS PRIMARY KEY:
TASK
ID START_DATE
1 22/09/21
2 21/09/21
3 20/09/21
这是我的代码:
CREATE TABLE EMPLOYEE AS
(SELECT * FROM TASK)
PARTITION BY RANGE ("START_DATE")
SUBPARTITION BY LIST("ID")
PARTITION P1 VALUES LESS THAN TO_DATE('20210920','YYYYYMMDD') (
SUBPARTITION S1 VALUES (1),
SUBPARTITION S2 VALUES (2),
SUBPARTITION S3 VALUES (3)
),
PARTITION P2 VALUES LESS THAN TO_DATE('20210921','YYYYYMMDD') (
SUBPARTITION S4 VALUES (1),
SUBPARTITION S5 VALUES (2),
SUBPARTITION S6 VALUES (3)
),
PARTITION P3 VALUES LESS THAN TO_DATE('20210922','YYYYYMMDD') (
SUBPARTITION S7 VALUES (1),
SUBPARTITION S8 VALUES (2),
SUBPARTITION S9 VALUES (3)
),
PARTITION P4 VALUES LESS THAN MAXVALUE (
SUBPARTITION S10 VALUES (1),
SUBPARTITION S11 VALUES (2),
SUBPARTITION S12 VALUES (3)
)
我该怎么做,这对我来说很重要,我收到了这个错误,我想当我更正它时我会收到另一个错误:
00933. 00000 - "SQL command not properly ended"
一个例子
SQL> create table task ( id number , start_date date ) ;
Table created.
SQL> CREATE TABLE t2
2 PARTITION BY RANGE (START_DATE)
3 SUBPARTITION BY LIST (ID)
4 (
5 PARTITION P1 VALUES LESS THAN (TO_DATE('2021-07-20','YYYY-MM-DD'))
6 (
7 SUBPARTITION S1 VALUES (1),
8 SUBPARTITION S2 VALUES (2),
9 SUBPARTITION S3 VALUES (3)
10 ),
11 PARTITION P2 VALUES LESS THAN (TO_DATE('2021-08-20','YYYY-MM-DD'))
12 (
13 SUBPARTITION S4 VALUES (1),
14 SUBPARTITION S5 VALUES (2),
15 SUBPARTITION S6 VALUES (3)
16 )
17 )
18* as select * from task
SQL> /
Table created.
注意事项
- 在构造的最后使用表达式
as select * from xxx
。 - 记住每个分区和子分区构造的括号。
- 虽然我没有把它放在我的示例中,但尝试使用子分区模板。
我会推荐一个 INTERVAL
分区和子分区模板。会是这个吗:
CREATE TABLE EMPLOYEE (
...
)
PARTITION BY RANGE (START_DATE) INTERVAL (INTERVAL '1' DAY)
SUBPARTITION BY LIST (ID)
SUBPARTITION TEMPLATE (
SUBPARTITION S1 VALUES (1),
SUBPARTITION S2 VALUES (2),
SUBPARTITION S3 VALUES (3)
)
( PARTITION P_INITIAL VALUES LESS THAN (TIMESTAMP '2021-09-01 00:00:00') SEGMENT CREATION DEFERRED );