SELECT ADD_MONTHS(to_date('2008-06-30','yyyy-mm-dd'),-1) FROM dual;
 本来按道理出来 的应该是2008-05-30怎么出来的是2008-05-31,
  想出来上个月的今天,例如2008-06-25 出来应该是2008-05-25

解决方案 »

  1.   

    add_months
    里一个重要概念
    如果基准日是一个月的最后天,那计算后的日期也是该月的最后天
      

  2.   

    比如说
    SELECT ADD_MONTHS(to_date('2008-02-29','yyyy-mm-dd'),1) FROM dual
    求今年2.29加一个月,答案是3.31
    SELECT ADD_MONTHS(to_date('2008-02-28','yyyy-mm-dd'),1) FROM dual
    答案是3.28
      

  3.   

    也就说你想通过今年2月份用add_months求出3.29,3.30是不可能的(如果是平常年份,连3.28也求不出)
      

  4.   

    谁知道ADD_MONTHS函数的内容在哪里啊,我想看看
      

  5.   

    参考: http://topic.csdn.net/t/20061130/11/5196346.html另SQL Reference: 
    Purpose
    ADD_MONTHS returns the date d plus n months. The argument n can be any integer. If d is the last day of the month or if the resulting month has fewer days than the day component of d, then the result is the last day of the resulting month. Otherwise, the result has the same day component as d.