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

前端 未结 1 1545
走了就别回头了
走了就别回头了 2020-12-24 11:59

I want to find records in a (Oracle SQL) table using the creation date field where records are older than 30 days. It would be nice to find records using a operators like >

相关标签:
1条回答
  • 2020-12-24 12:30

    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)
    
    0 讨论(0)
提交回复
热议问题