Oracle

Oracle 日期或時間戳 PARTITION 列

  • January 11, 2022

是否可以發出查詢來判斷 PARTITION 列是日期還是時間戳。

例如,這應該返回時間戳


CREATE TABLE ts (
num_val NUMBER(6),
ts_val TIMESTAMP)
 PARTITION BY RANGE (ts_val) 
 INTERVAL ( NUMTODSINTERVAL (1, 'DAY') ) ( 
   PARTITION OLD_DATA VALUES LESS THAN (TIMESTAMP '2021-01-01 00:00:00.000000')
 );

這應該返回日期


CREATE TABLE dts (
  dt   DATE
)
PARTITION BY RANGE (dt)
INTERVAL (NUMTODSINTERVAL(7,'DAY'))
(
  PARTITION OLD_DATA values LESS THAN (TO_DATE('2022-01-01','YYYY-MM-DD'))
);

使用這個:

SELECT TABLE_NAME, PARTITIONING_TYPE, COLUMN_NAME, DATA_TYPE
FROM USER_PART_TABLES 
   JOIN USER_PART_KEY_COLUMNS ON NAME = TABLE_NAME
   JOIN USER_TAB_COLS USING (TABLE_NAME, COLUMN_NAME)
where OBJECT_TYPE = 'TABLE';

引用自:https://dba.stackexchange.com/questions/305911