我想以一种我始终知道记录去向的方式对表进行分区。例如,如果我有一个电话列表和 10 个分区,我想根据每个电话号码的最后一位来引导它。
值得一提的是我使用的是 Oracle 11gR2
PARTITION BY LIST
但是,似乎不允许这样做。
CREATE TABLE t (
tel INT NOT NULL
)
PARTITION BY LIST ( MOD (tel,10) )
(PARTITION MSISDN0 VALUES (0),
PARTITION MSISDN1 VALUES (1),
PARTITION MSISDN2 VALUES (2),
PARTITION MSISDN3 VALUES (3),
PARTITION MSISDN4 VALUES (4),
PARTITION MSISDN5 VALUES (5),
PARTITION MSISDN6 VALUES (6),
PARTITION MSISDN7 VALUES (7),
PARTITION MSISDN8 VALUES (8),
PARTITION MSISDN9 VALUES (9));
Erro de SQL: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
LIST PARTITIONS
似乎不接受函数。我仍然使用虚拟专栏进行管理:
CREATE TABLE t (
tel INT NOT NULL
, tel_p GENERATED ALWAYS AS ( mod (tel,10) )
)
PARTITION BY LIST ( tel_p )
(PARTITION MSISDN0 VALUES (0),
PARTITION MSISDN1 VALUES (1),
PARTITION MSISDN2 VALUES (2),
PARTITION MSISDN3 VALUES (3),
PARTITION MSISDN4 VALUES (4),
PARTITION MSISDN5 VALUES (5),
PARTITION MSISDN6 VALUES (6),
PARTITION MSISDN7 VALUES (7),
PARTITION MSISDN8 VALUES (8),
PARTITION MSISDN9 VALUES (9));
虽然感觉有点不靠谱... 是否有“正确的方法”来做到这一点?
最佳答案
我认为您的做法是正确的方式。您可以在 Oracle 的文档中具体阅读该功能:
Virtual Column-Based Partitioning
In previous releases of the Oracle Database, a table could only be partitioned if the partitioning key physically existed in the table. In Oracle Database 11g, virtual columns remove that restriction and allow the partitioning key to be defined by an expression, using one or more existing columns of a table. The expression is stored as metadata only.
Oracle Partitioning has been enhanced to allow a partitioning strategy to be defined on virtual columns. For example, a 10 digit account ID can include account branch information as the leading 3 digits. With the extension of virtual column based Partitioning, an ACCOUNTS table containing an ACCOUNT_ID column can be extended with a virtual (derived) column ACCOUNT_BRANCH that is derived from the first three digits of the ACCOUNT_ID column, which becomes the partitioning key for this table.
Virtual column-based Partitioning is supported with all basic partitioning strategies, including interval and interval-* composite partitioning.
关于sql - 使用表达式按列表分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19594761/