1. 程式人生 > >Oracle表介紹--簇表

Oracle表介紹--簇表

簇其實就是一組表,是一組共享相同資料塊的多個表組成。 將經常一起使用的表組合在一起成簇可以提高處理效率。     在一個簇中的表就叫做簇表。建立順序是:簇→簇表→資料→簇索引    1、建立簇的 格式     CREATE CLUSTER cluster_name
    (column date_type [,column datatype]...)
    [PCTUSED 40 | integer] [PCTFREE 10 | integer]
    [SIZE integer]
    [INITRANS 1 | integer] [MAXTRANS 255 | integer]
    [TABLESPACE tablespace]
    [STORAGE storage]
   SIZE:指定估計平均簇鍵,以及與其相關的行所需的位元組數。    2、建立簇

create cluster my_clu (deptno number )

pctused 60

pctfree 10

size 1024

tablespace users

storage (

initial 128 k

next 128 k

minextents 2

maxextents 20

);

   3、建立簇表

create table t1_dept(

deptno number ,

dname varchar2 ( 20 )

)

cluster my_clu(deptno);

create table t1_emp(

empno number ,

ename varchar2 ( 20 ),

birth_date date ,

deptno number

)

cluster my_clu(deptno);

   4、為簇建立索引

create index clu_index on cluster my_clu;

    注:若不建立索引,則在插入資料時報錯:ORA-02032: clustered tables cannot be used before the cluster index is built 管理簇     使用ALTER修改簇屬性(必須擁有ALTER ANY CLUSTER的許可權)
   1、修改簇屬性     可以修改的簇屬性包括:     * PCTFREE、PCTUSED、INITRANS、MAXTRANS、STORAGE     * 為了儲存簇鍵值所有行所需空間的平均值SIZE     * 預設並行度     注:     * 不能修改INITIAL和MINEXTENTS的值     * PCTFREE、PCTUSED、SIZE引數修改後適用於所有資料塊     * INITRANS、MAXTRANS僅適用於以後分配的資料塊     * STORAGE引數修改後僅影響以後分配給簇的盤區     格式:

alter cluster my_clu

pctused 40

   2、刪除簇     drop cluster my_clu; -- 僅適用於刪除空簇

drop cluster my_clu including tables ; -- 刪除簇和簇表

drop cluster my_clu including tables cascade constraints ;

-- 同時刪除外來鍵約束

   注:簇表可以像普通表一樣刪除。 雜湊聚簇表     在簇表中,Oracle使用儲存在索引中的鍵值來定位表中的行,而在雜湊聚簇表中,使用了雜湊函式代替了簇索引,先通過內部函式或者自定義的函式進行雜湊計算,然後再將計算得到的碼值用於定位表中的行。建立雜湊簇需要用到HASHKEYS子句。    1、建立雜湊簇

create cluster my_clu_two(empno number(10) )

pctused 70

pctfree 10

tablespace users

hash is empno

hashkeys 150 ;

    說明:     * hash is 子句指明瞭進行雜湊的列,如果列是唯一的標示行,就可以將列指定為雜湊值     * hashkeys 指定和限制雜湊函式可以產生的唯一的雜湊值的數量    2、建立散列表

create table t2_emp (

empno number ( 10 ),

ename varchar2 ( 20 ),

birth_date date ,

deptno number )

cluster my_clu_two(empno);

    注意:     * 必須設定數值的精度(具體原因不詳)     * 雜湊簇不能也不用建立索引     * 雜湊簇不能ALTER:size、hashkeys、hash is引數

轉自:http://www.blogjava.net/wxqxs/archive/2008/10/19/238636.html