技术开发 频道

Oracle 11g新特性:更加灵活的分区策略

关联分区中要注意一点:关联分区中,父表不能为Interval分区。

11g,还新增了以虚字段(Virtual Column)为分区键的分区方式。以下例子中,store就是一个虚列,它的数值并没有实际存储在表中,而是由其它两个字段buy和sell计算得出,我们可以以它作为分区键建立分区:

SQL代码
SQL> create table par_vc(
2 itemid number,
3 buy number,
4 sell number,
5 store number as (buy - sell)
6 )
7 partition by range (store)
8 (
9 partition values less than (1000),
10 partition values less than (2000),
11 partition values less than (maxvalue)
12 );

Table created.

11g中引入的最后一种特殊的分区是system partition。对于普通分区,必须有一个或多个字段做为分区键来建立分区,而system分区就没有这种要求——仅仅是将表的数据分别存储在多个段中,而你在插入数据时,需要指定数据存储在哪个分区上:

SQL代码
SQL> create table par_sys (a number, b varchar2(10))
2 partition by system
3 (
4 partition p1,
5 partition p2
6 );

Table created.

SQL> insert into par_sys values (1, 'a');
insert into par_sys values (1, 'a')
*
ERROR at line 1:
ORA-14701: partition-extended name or bind variable must be used for DMLs on
tables partitioned by the System method


SQL> insert into par_sys partition(p1) values (1, 'a');

1 row created.

从上面的例子可以注意到:在插入数据时,如果没有指定分区就会抛错。
 

0
相关文章