Oracle11g新特性虛擬列分區
現在有個需求:一個單據表要按照月份來分區,如果是在Oracle 10g上,只能再加一個字段。在Oracle 11g以後就不一樣了,可以用虛擬列處理。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> create table t_virtual
(
object_id number,
object_name varchar2(100),
created date
)
partition by list(to_number(to_char(created, 'MM')))
(
partition P1 VALUES (1),
partition P2 VALUES (2),
partition P3 VALUES (3),
partition P4 VALUES (4),
partition P5 VALUES (5),
partition P6 VALUES (6),
partition P7 VALUES (7),
partition P8 VALUES (8),
partition P9 VALUES (9),
partition P10 VALUES (10),
partition P11 VALUES (11),
partition P12 VALUES (12)
);
partition by list(to_number(to_char(created, 'MM')))
*
第 7 行出現錯誤:
ORA-00907: 缺失右括號
SQL> create table t_virtual
(
object_id number,
object_name varchar2(100),
created date,
create_year AS (to_number(to_char(created, 'MM')))
)
partition by list(create_year)
(
partition P1 VALUES (1),
partition P2 VALUES (2),
partition P3 VALUES (3),
partition P4 VALUES (4),
partition P5 VALUES (5),
partition P6 VALUES (6),
partition P7 VALUES (7),
partition P8 VALUES (8),
partition P9 VALUES (9),
partition P10 VALUES (10),
partition P11 VALUES (11),
partition P12 VALUES (12)
);
表已創建。