简体   繁体   中英

Delete rows older than 1 month

I have this Oracle table which I would like to delete rows if they are older than 1 month?

CREATE TABLE EVENTS(
  EVENTID INTEGER NOT NULL,
  SOURCE VARCHAR2(50 ),
  TYPE VARCHAR2(50 ),
  EVENT_DATE DATE,
  DESCRIPTION VARCHAR2(100 )
)
/

Also how I can delete rows of the total size of the table is for example 100 MB?

You should be able to do something like

DELETE FROM EVENTS
  WHERE EVENT_DATE < ADD_MONTHS(SYSDATE, -1);

Best of luck.

EDIT (see OP's comment below regarding XML)

Without knowing how you're obtaining or using the XML value it's hard to say but perhaps something like

DELETE FROM EVENTS
  WHERE EVENT_DATE < ADD_MONTHS(SYSDATE, XMLvalue * -1);

where XMLvalue is the value you get from the XML.

Best of luck.

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