SQL> create table aaaaa (a char(10),b date);表已创建。SQL> select a,b,months_between(last_day(sysdate),last_day(to_date(b,'yyyy-mm-dd')))
  2  from aaaaa
  3  where months_between(last_day(sysdate),last_day(to_date(b,'yyyy-mm-dd'))) >= 1
  4  order by b;未选定行SQL> select a,b,months_between(last_day(sysdate),last_day(to_date(b,'yyyy-mm-dd')))
  2  from aaaaa
  3  where months_between(last_day(sysdate),last_day(to_date(b,'yyyy-mm-dd'))) = 1
  4  order by b;未选定行好像没有什么问题

解决方案 »

  1.   

    b:date
    怎用了to_date()函数呢,非法的.select a,b,months_between(last_day(sysdate),last_day(b))
    from table
    where months_between(last_day(sysdate),last_day(b)) >= 1
    order by b;
      

  2.   

    1 加上order by也可以用 
    To_date(b,'yyyy-mm-dd')2 不明白?返回的是月数 怎么会不能比较大小呢?
      

  3.   

    楼主意思只是计算相差月份:
    select a,b,months_between(trunc(sysdate,'mm'),trunc(b,'mm'))
    from table
    where months_between(trunc(sysdate,'mm'),trunc(b,'mm'))>= 1
    order by b;
      

  4.   

    select a ,b,sysdate-b c from table where to_number(c)>=1 order by b;
      

  5.   

    怎么可能存在年问题:
    SQL> select months_between(to_date('2003-1-10','yyyy-mm-dd'),to_date('2002-6-10','yyyy-mm-dd')) from dual;MONTHS_BETWEEN(TO_DATE('2003-1
    ------------------------------
                                 7
      

  6.   

    Sorry,To_be is:
    select a,b,to_number(to_char(sysdate,'yyyymmdd'))-to_number(to_char(b,'yyyymmdd')) c from table where c>=1 order by b;
      

  7.   

    如果仅算月份,这样:
    select a,b,to_number(to_char(sysdate,'yyyymm'))-to_number(to_char(b,'yyyymm')) c from table where c>=1 order by b;
      

  8.   

    这样是可以啊我就是这么写的,我是说你刚才那个trunc就没有考虑到
    我的语句没有问题问题在于数据,比方我在where 条件中加一个rownum<24就可以,>=24就不行
      

  9.   

    各位朋友,小弟近日正在学习oracle,由于授课教师水平很戳,所以学习没有多大进展,本人想请各位朋友帮我找一些oracle的电子文档或幻灯片,以助我学习提高,小弟感激不尽.来信请发:
    [email protected]