簇其实就是一组表,是一组共享相同数据块的多个表组成。 将经常一起使用的表组合在一起成簇可以提高处理效率。在一个簇中的表就叫做簇表。建立顺序是:簇→簇表→数据→簇索引
1、创建簇
create cluster scott.t_clu
(
deptno number
)
tablespace users;
2、创建簇表
create table scott.t_dept
(
deptno number,
dname varchar2(10)
)
cluster scott.t_clu(deptno);
create table scott.t_emp
(
empno number,
ename varchar2(10),
deptno number
)
cluster scott.t_clu(deptno);
3、为簇创建索引
create index scott.ind_t_clu on cluster scott.t_clu;
注:若不创建索引,则在插入数据时报错:ORA-02032: clustered tables cannot be used before the cluster index is built
SQL> insert into scott.t_dept select deptno,dname from scott.dept;
SQL> insert into scott.t_emp select empno,ename,deptno from scott.emp;
SQL> commit;
管理簇
1、修改簇属性
alter cluster scott.t_clu
pctfree 20
initrans 4;
2、删除簇
drop cluster t_clu; --仅适用于删除空簇
drop cluster t_clu including tables; --删除簇和簇表
drop cluster t_clu including tables cascade constraints; --同时删除外键约束
散列聚簇表
在簇表中,Oracle使用存储在索引中的键值来定位表中的行,而在散列聚簇表中,使用了散列函数代替了簇索引,先通过内部函数或者自定义的函数进行散列计算,然后再将计算得到的码值用于定位表中的行。创建散列簇需要用到HASHKEYS子句
1、创建散列簇
create cluster scott.t_clu2
(
empno number(10)
)
tablespace users
hashkeys 10
hash is empno;
2、创建散列表
create table scott.t_emp2
(
empno number(10),
ename varchar2(10),
deptno number
)
cluster scott.t_clu2(empno);
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17012874/viewspace-694191/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/17012874/viewspace-694191/