Database

Oracle SQL Where clause to find date records older than 30 days

steloflute 2013. 1. 16. 23:30

http://stackoverflow.com/questions/3860295/oracle-sql-where-clause-to-find-date-records-older-than-30-days

 

Use:

SELECT *
  FROM YOUR_TABLE
 WHERE creation_date <= TRUNC(SYSDATE) - 30

SYSDATE returns the date & time; TRUNC resets the date to being as of midnight so you can omit it if you want the creation_date that is 30 days previous including the current time.

Depending on your needs, you could also look at using ADD_MONTHS:

SELECT *
  FROM YOUR_TABLE
 WHERE creation_date <= ADD_MONTHS(TRUNC(SYSDATE), -1)

 

 

 

'Database' 카테고리의 다른 글

(Oracle) alert.log location: bdump  (0) 2013.01.18
(Oracle) table backup  (0) 2013.01.18
(Oracle) Comparing Dates  (0) 2013.01.04
(Oracle) delete 복구  (0) 2012.11.09
(Oracle) data pump 권한 주기  (0) 2012.11.05