How to partition an oracle table by a date column?

情到浓时终转凉″ 提交于 2019-11-30 17:29:59

问题


I have a table in oracle:

CREATE TABLE transaction (
    id INT NOT NULL,
    accountnumber VARCHAR NOT NULL,
    stmtvaluedate DATE NOT NULL,
    ...
)

And I want to partition this table by the stmtvaluedate column. My goal is to create a new partition after a month have passed.

Is there any good script, for it? Or I have to create static numbers of partitions?

The best would be: if a month have passed, a new partition will be created automatically.

Can anyone give me an example about how to partition a table by a date column after every month? If the automatically partitioning is impossible, than I would need an example, which creates partitions to a year from now by a date column, about every month.

Thanks!


回答1:


What you want to do is completely possible. This should do it:

CREATE TABLE transaction (
    id INT NOT NULL,
    accountnumber VARCHAR2(30) NOT NULL,
    stmtvaluedate DATE NOT NULL
)
PARTITION BY RANGE (stmtvaluedate)
INTERVAL (NUMTOYMINTERVAL (1,'MONTH')) 
    ( partition transaction_old values less than (to_date('01-JAN-2000','DD-MON-YYYY') ));


来源:https://stackoverflow.com/questions/33808347/how-to-partition-an-oracle-table-by-a-date-column

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