昨天在建一分区表时抛了异常“ORA-14039: 分区列必须构成 UNIQUE 索引的关键字列子集”,具体过程如下:
[@more@]SQL> begin
2 execute immediate
3 'create table MSG_STORAGE_CACHE
4 (
5 NAME VARCHAR2(64) not null,
6 HASHKEY VARCHAR2(100) not null,
7 PACKAGE VARCHAR2(3000) not null,
8 CREATEDATE DATE default SYSDATE
9 )
10 partition by range(CREATEDATE)
11 (
12 partition p_'||to_char(sysdate-6,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-5,'yyyymmdd')||''',''yyyymmdd'')),
13 partition p_'||to_char(sysdate-5,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-4,'yyyymmdd')||''',''yyyymmdd'')),
14 partition p_'||to_char(sysdate-4,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-3,'yyyymmdd')||''',''yyyymmdd'')),
15 partition p_'||to_char(sysdate-3,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-2,'yyyymmdd')||''',''yyyymmdd'')),
16 partition p_'||to_char(sysdate-2,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate-1,'yyyymmdd')||''',''yyyymmdd'')),
17 partition p_'||to_char(sysdate-1,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate,'yyyymmdd')||''',''yyyymmdd'')),
18 partition p_'||to_char(sysdate,'yyyymmdd')||' values less than(to_date('''||to_char(sysdate+1,'yyyymmdd')||''',''yyyymmdd''))
19 )';
20 end;
21 /
PL/SQL procedure successfully completed
SQL>
SQL> alter table MSG_STORAGE_CACHE
2 add constraint PK_MSG_STORAGE_CACHE primary key(HASHKEY,NAME) using index local;
alter table MSG_STORAGE_CACHE
add constraint PK_MSG_STORAGE_CACHE primary key(HASHKEY,NAME) using index local
ORA-14039: 分区列必须构成 UNIQUE 索引的关键字列子集
SQL>
原来oracle不支持在分区表上创建PK主键时主键列不包含分区列,创建另外的约束(unique)也不可以。
为了解决这个问题,两种方法:1、将CREATEDATE 列也加上pk列中,采用alter table MSG_STORAGE_CACHE
add constraint PK_MSG_STORAGE_CACHE primary key(HASHKEY,NAME,CREATEDATE) using index local;
2、创建index好了create index indx_MSG_STORAGE_CACHE on MSG_STORAGE_CACHE(HASHKEY,NAME) local;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/38542/viewspace-970712/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/38542/viewspace-970712/