Oracle: Partition table by month

馋奶兔 提交于 2019-12-12 03:45:32

问题


My solution(months in german):

PARTITION BY LIST ((to_char(GEBURTSDATUM, 'Month'))) 
(  
  PARTITION p1 VALUES('JANUAR'),  
  PARTITION p2 VALUES('Februar'), 
  PARTITION p3 VALUES('MÄRZ'),  
  PARTITION p4 VALUES('APRIL'), 
  PARTITION p5 VALUES('MAI'),  
  PARTITION p6 VALUES('JUNI'), 
  PARTITION p7 VALUES('JULI'), 
  PARTITION p8 VALUES('AUGUST'),
  PARTITION p9 VALUES('SEPTEMBER'),
  PARTITION p10 VALUES('OKTOBER'), 
  PARTITION p11 VALUES('NOVEMBER'),
  PARTITION p12 VALUES('DEZEMBER') 
);  

This doesn't work because of the to_char function.


回答1:


In 11g you can use function-based partitioning through defining a virtual column: http://www.oracle-base.com/articles/11g/partitioning-enhancements-11gr1.php#virtual_column_based_partitioning

Otherwise, you must manually define and maintain a separate column for the partitioning month.

I'd suggest using month numbers instead of names in either case.




回答2:


If the table has a date column, the statement below can be used as an example for monthly partitioning starting from today (Oracle 11g):

PARTITION BY RANGE (date_column)
            INTERVAL (NUMTODSINTERVAL(1,'month') )
             (PARTITION p_first VALUES LESS THAN ('16-MAY-2016'));


来源:https://stackoverflow.com/questions/14202945/oracle-partition-table-by-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!