---
title: "月日比较"
author: "oyprunner"
date: "2010-02-23T17:58:18Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2010-02-23T17:58:18Z"
id: 600955
url: "https://oyprunner.iteye.com/blog/600955"
---

```sql
select substr(('0' || Extract(MONTH from ins.t_end_date)), 2) ||
       substr(('0' || Extract(DAY from ins.t_end_date)), -2),
       substr('0' ||
              Extract(MONTH from
                      to_date(to_char(add_months(sysdate, 3), 'yyyy-mm-dd'),
                              'yyyy-mm-dd')),
              2) ||
       substr('0' || Extract(DAY FROM to_date(to_char(add_months(sysdate, 3),
                                             'yyyy-mm-dd'),
                                     'yyyy-mm-dd')),
              2)
  from tb_ins_info ins
 where ins.c_del = '0'
   and ins.c_stat = '99'
   and ins.c_cst_id = '23'
   and substr(('0' || Extract(MONTH from ins.t_end_date)), 2) ||
       substr(('0' || Extract(DAY from ins.t_end_date)), -2) <=
       substr('0' ||
              Extract(MONTH from
                      to_date(to_char(add_months(sysdate, 3), 'yyyy-mm-dd'),
                              'yyyy-mm-dd')),
              2) ||
       substr('0' || Extract(DAY FROM to_date(to_char(add_months(sysdate, 3),
                                             'yyyy-mm-dd'),
                                     'yyyy-mm-dd')),
              2)
   and ins.t_end_date > sysdate
```