Oracle分割槽表基礎運維-04列表分割槽

chenoracle發表於2020-05-15

Oracle分割槽表基礎運維 -04列表分割槽

List Partitioning

List partitioning enables you to explicitly control how rows map to partitions by specifying a list of discrete values for the partitioning key in the description for each partition.

The advantage of list partitioning is that you can group and organize unordered and unrelated sets of data in a natural way. For a table with a region column as the partitioning key, the East Sales Region partition might contain values New York,Virginia, and Florida.

The DEFAULT partition enables you to avoid specifying all possible values for a list - partitioned table by using a default partition, so that all rows that do not map to any other partition do not generate an error.

--注意,此分割槽為列表分割槽

create table list_part_tab (id number,deal_date date,area_code number,contents varchar2(4000))
partition by list (area_code)
(
partition p_591 values  (591),
partition p_592 values  (592),
partition p_593 values  (593),
partition p_594 values  (594),
partition p_595 values  (595),
partition p_596 values  (596),
partition p_597 values  (597),
partition p_598 values  (598),
partition p_599 values  (599),
partition p_other values  (DEFAULT)
);

--以下是插入一整年日期隨機數和表示福建地區號含義(591到599)的隨機數記錄,共有10萬條,如下:

insert into list_part_tab
  (id, deal_date, area_code, contents)
  select rownum,
         to_date(to_char(sysdate - 365, 'J') +
                 TRUNC(DBMS_RANDOM.VALUE(0, 365)),
                 'J'),
         ceil(dbms_random.value(590, 599)),
         rpad('*', 400, '*')
    from dual
  connect by rownum <= 100000;
commit;

---檢視當前使用者下有哪些分割槽表

select
 TABLE_NAME 
from
 user_tables a 
where
 a.partitioned
=
'YES'
;

---檢視分割槽表名,分割槽名,表空間等資訊

select table_name, partition_name, tablespace_name, high_value
  from user_tab_partitions
 where table_name = 'LIST_PART_TAB';

---檢視地區 資料 分佈

select count(*), area_code
  from LIST_PART_TAB
 group by area_code
 order by 2;


---檢視地區分佈 插入非分割槽值,資料會插入到default分割槽下

insert into LIST_PART_TAB values(1,to_date('2020-05-15','yyyy-mm-dd'),100,'abc');
commit;

---檢視地區 資料 分佈

select dbms_rowid.rowid_object(rowid) obj_id, count(*)
  from LIST_PART_TAB
 group by dbms_rowid.rowid_object(rowid)
 order by 1;

select
 
*
 
from
 LIST_PART_TAB 
partition
(
P_OTHER
)
;

歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2692491/,如需轉載,請註明出處,否則將追究法律責任。

相關文章