簇和簇表

簇其实就是一组表,是一组共享相同数据块的多个表组成。 将经常一起使用的表组合在一起成簇可以提高处理效率。在一个簇中的表就叫做簇表。建立顺序是:簇→簇表→数据→簇索引


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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值