Thứ Ba, 1 tháng 12, 2020

Tạo bảng Hash Partition trong Oracle Database

--Tạo bảng sales hash partition 

CREATE TABLE sales_hash
  (s_productid  NUMBER,
   s_saledate   DATE,
   s_custid     NUMBER,
   s_totalprice NUMBER)
PARTITION BY HASH(s_productid)
( PARTITION p1 TABLESPACE tbs1
, PARTITION p2 TABLESPACE tbs2
, PARTITION p3 TABLESPACE tbs3
, PARTITION p4 TABLESPACE tbs4
);


--Tạo  composite range-hash partitioned table dùng mệnh đề STORE IN 

CREATE TABLE sales

  ( prod_id       NUMBER(6)

  , cust_id       NUMBER

  , time_id       DATE

  , channel_id    CHAR(1)

  , promo_id      NUMBER(6)

  , quantity_sold NUMBER(3)

  , amount_sold   NUMBER(10,2)

  )

 PARTITION BY RANGE (time_id) SUBPARTITION BY HASH (cust_id)

  SUBPARTITIONS 8 STORE IN (ts1, ts2, ts3, ts4)

 ( PARTITION sales_q1_2006 VALUES LESS THAN (TO_DATE('01-APR-2006','dd-MON-yyyy'))

 , PARTITION sales_q2_2006 VALUES LESS THAN (TO_DATE('01-JUL-2006','dd-MON-yyyy'))

 , PARTITION sales_q3_2006 VALUES LESS THAN (TO_DATE('01-OCT-2006','dd-MON-yyyy'))

 , PARTITION sales_q4_2006 VALUES LESS THAN (TO_DATE('01-JAN-2007','dd-MON-yyyy'))

 );

--Tạo bảng với composite range-hash partitioning

CREATE TABLE page_history

( id                NUMBER NOT NULL

, url               VARCHAR2(300) NOT NULL

, view_date         DATE NOT NULL

, client_ip         VARCHAR2(23) NOT NULL

, from_url          VARCHAR2(300)

, to_url            VARCHAR2(300)

, timing_in_seconds NUMBER

) PARTITION BY RANGE(view_date) INTERVAL (NUMTODSINTERVAL(1,'DAY'))

SUBPARTITION BY HASH(client_ip)

SUBPARTITIONS 32

(PARTITION p0 VALUES LESS THAN (TO_DATE('01-JAN-2006','dd-MON-yyyy')))

PARALLEL 32 COMPRESS;


CREATE  TABLE ABC(

id VARCHAR2(100) primary key,

datecreated DATE)

PARTITION BY RANGE (datecreated) INTERVAL (NUMTODSINTERVAL(1,'DAY'))

  SUBPARTITION BY HASH (ID) SUBPARTITIONS 4

 (PARTITION lessthan2018  VALUES LESS THAN (TIMESTAMP' 2018-01-01 00:00:00') );

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master