Oracle分割槽表基礎運維-02範圍分割槽
Oracle 分割槽表基礎運維 -02 範圍分割槽
Range Partitioning
Range partitioning maps data to partitions based on ranges of values of the partitioning key that you establish for each partition.
Range partitioning is the most common type of partitioning and is often used with dates. For a table with a date column as the partitioning key, the January-2017 partition would contain rows with partitioning key values from 01-Jan-2017 to 31-Jan-2017.
Each partition has a VALUES LESS THAN clause, that specifies a non-inclusive upper bound for the partitions. Any values of the partitioning key equal to or higher than this
literal are added to the next higher partition. All partitions, except the first, have an implicit lower bound specified by the VALUES LESS THAN clause of the previous partition.
A MAXVALUE literal can be defined for the highest partition. MAXVALUE represents a virtual infinite value that sorts higher than any other possible value for the partitioning key, including the NULL value.
建立範圍分割槽表 range_part_tab
create table range_part_tab ( id number , deal_date date , area_code number , contents varchar2 ( 4000 ))
partition by range ( deal_date )
(
partition p1 values less than ( TO_DATE ( '2019-06-01' , 'YYYY-MM-DD' )),
partition p2 values less than ( TO_DATE ( '2019-07-01' , 'YYYY-MM-DD' )),
partition p3 values less than ( TO_DATE ( '2019-08-01' , 'YYYY-MM-DD' )),
partition p4 values less than ( TO_DATE ( '2019-09-01' , 'YYYY-MM-DD' )),
partition p5 values less than ( TO_DATE ( '2019-10-01' , 'YYYY-MM-DD' )),
partition p6 values less than ( TO_DATE ( '2019-11-01' , 'YYYY-MM-DD' )),
partition p7 values less than ( TO_DATE ( '2019-12-01' , 'YYYY-MM-DD' )),
partition p8 values less than ( TO_DATE ( '2020-01-01' , 'YYYY-MM-DD' )),
partition p9 values less than ( TO_DATE ( '2020-02-01' , 'YYYY-MM-DD' )),
partition p10 values less than ( TO_DATE ( '2020-03-01' , 'YYYY-MM-DD' )),
partition p11 values less than ( TO_DATE ( '2020-04-01' , 'YYYY-MM-DD' )),
partition p12 values less than ( TO_DATE ( '2020-05-01' , 'YYYY-MM-DD' )),
partition p_max values less than ( maxvalue )
);
插入資料:
---插入一整年日期隨機數和表示福建地區號含義(591到599)的隨機數記錄,共有10萬條,如下:
insert into range_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 ;
函式說明:
ceil(n) 取大於等於數值n的最小整數;
floor(n)取小於等於數值n的最大整數
;
select ceil ( 9.1 ), floor ( 9.1 ), ceil ( 9.9 ), floor ( 9.9 ) from dual ;
lpad( string1, padded_length, [ pad_string ] )
rpad( string1, padded_length, [ pad_string ] )
select rpad ( 'CJC' , 10 , '*' ), lpad ( 'CJC' , 10 , '*' ) from dual ;
檢視分割槽表資訊
---檢視當前使用者下有哪些分割槽表
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 = 'RANGE_PART_TAB' ;
---檢視high_value
with xs as
( select x. *,
to_date ( substr ( high_value , 11 , 19 ), 'YYYY-MM-DD HH24:MI:SS' ) dates ,
replace ( high_value , 'TIMESTAMP''' ) datestr
from xmltable ( '/ROWSET/ROW' passing ( select dbms_xmlgen.getxmltype ( '
select t.table_owner, t.table_name, t.partition_name, t.high_value
from dba_tab_partitions t' )
from dual ) columns table_owner varchar2 ( 30 ) path
'TABLE_OWNER' ,
table_name varchar2 ( 30 ) path 'TABLE_NAME' ,
partition_name varchar2 ( 30 ) path 'PARTITION_NAME' ,
high_value varchar2 ( 30 ) path 'HIGH_VALUE' ) x )
select xs.datestr , p.table_name , p.partition_name , p.tablespace_name
from xs , dba_tab_partitions p
where xs.table_owner = 'CJC'
and p.table_owner = xs.table_owner
and p.table_name = xs.table_name
and p.partition_name = xs.partition_name
order by p.table_owner , p.table_name , p.partition_position ;
SQL> SELECT P.TABLE_NAME, P.PARTITION_NAME, P.HIGH_VALUE FROM USER_TAB_PARTITIONS P;
---檢視時間分佈
select count (*) from RANGE_PART_TAB partition ( P1 );
select count (*) from RANGE_PART_TAB partition ( P2 );
select count (*) from RANGE_PART_TAB partition ( P3 );
select count (*), to_char ( deal_date , 'yyyy-mm' )
from RANGE_PART_TAB
group by to_char ( deal_date , 'yyyy-mm' )
order by 2 ;
---通過object_id檢視每個分割槽資料分佈情況
select * from dba_segments where segment_name = 'RANGE_PART_TAB' ;
select * from dba_objects where object_name = 'RANGE_PART_TAB' ;
select dbms_rowid.rowid_object ( rowid ) obj_id , count (*)
from RANGE_PART_TAB
group by dbms_rowid.rowid_object ( rowid )
order by 1 ;
歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2692263/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle分割槽表基礎運維-07增加分割槽(1範圍分割槽)Oracle運維
- Oracle分割槽表基礎運維-04列表分割槽Oracle運維
- Oracle分割槽表基礎運維-09刪除分割槽Oracle運維
- Oracle分割槽表基礎運維-05組合分割槽Oracle運維
- Oracle分割槽表基礎運維-03HASH分割槽Oracle運維
- Oracle分割槽表基礎運維-07增加分割槽(2 HASH分割槽)Oracle運維
- Oracle分割槽表基礎運維-07增加分割槽(3列表分割槽)Oracle運維
- Oracle分割槽表基礎運維-06分割槽表索引Oracle運維索引
- Oracle分割槽表基礎運維-01分割槽表分類Oracle運維
- Oracle分割槽表基礎運維-07增加分割槽(4 RANGE_HASH)Oracle運維
- Oracle分割槽表基礎運維-07增加分割槽(5RANGE_LIST)Oracle運維
- Oracle分割槽表基礎運維-07增加分割槽(6RANGE_RANGE)Oracle運維
- Oracle分割槽表基礎運維-08Coalescing PartitionsOracle運維
- 範圍分割槽
- oracle分割槽表和分割槽表exchangeOracle
- oracle分割槽表和非分割槽表exchangeOracle
- 檢視分割槽範圍
- [oracle] expdp 匯出分割槽表的分割槽Oracle
- oracle 分割槽表move和包含分割槽表的lob moveOracle
- ORACLE分割槽表梳理系列Oracle
- PostgreSQL/LightDB 分割槽表之分割槽裁剪SQL
- oracle 線上重新定義,普通表改變分割槽表,分割槽表可以更改型別、分割槽欄位等Oracle型別
- oracle將表配置為分割槽表Oracle
- oracle 普通表-分割槽表改造流程Oracle
- 非分割槽錶轉換成分割槽表
- Oracle 12.2之後ALTER TABLE .. MODIFY轉換非分割槽表為分割槽表Oracle
- PG的非分割槽表線上轉分割槽表
- 【MYSQL】 分割槽表MySql
- 對oracle分割槽表的理解整理Oracle
- Oracle SQL調優之分割槽表OracleSQL
- Oracle12c:建立主分割槽、子分割槽,實現自動分割槽插入效果Oracle
- 移動分割槽表和分割槽索引的表空間索引
- Oracle drop分割槽表單個分割槽無法透過閃回恢復Oracle
- 【Linux】MBR磁碟分割槽表只能有四個分割槽?Linux
- Linux交換分割槽相關都有哪些命令?Linux運維基礎Linux運維
- Oracle 12C新特性-線上把非分割槽錶轉為分割槽表Oracle
- ORACLE刪除-表分割槽和資料Oracle
- MySQL 分割槽表探索MySql