简体   繁体   中英

How to partition an oracle table by a date column?

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!

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') ));

I crated below table with month wise partition CREATE TABLE DEMO

  ( 
   business_date date
  )
 PARTITION BY RANGE (business_date) INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
 (PARTITION p1 VALUES LESS THAN (TO_DATE('01-JAN-2019','dd-MON-yyyy'))
  );

 insert into DEMO values('27-SEP-20')\n

insert into DEMO values('21-SEP-19')
insert into DEMO values('27-JUN-20')

Here oracle four partition created one with P1 and other 3 with SYS P277.. like.

I am trying to do select query from my spring boot API, how i will do that. if we don't know the remaining three Partition name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM