年:to_char(yourdate,'yyyy')
月:to_char(yourdate,'mm')
日:to_char(yourdate,'dd')

解决方案 »

  1.   

    select B.* from 
    A,B
    where A.af1=B.bf1
    and abs(to_number(to_char(A.af2,'YYYY'))-to_number(to_char(A.af2,'YYYY')))
    between 0 and 10
      

  2.   


    select count(*) from B where exists (
    select 1 from a where a.af1=b.bf1 and abs(b.bf2-a.af2)>0 and abs(b.bf2-a.af2)<10)月
    select count(*) from B where exists (
    select 1 from a where a.af1=b.bf1 and abs(b.bf2-a.af2)/30>0 and abs(b.bf2-a.af2)/30<10)年
    select count(*) from B where exists (
    select 1 from a where a.af1=b.bf1 and abs(b.bf2-a.af2)/30*12>0 and abs(b.bf2-a.af2)/30*12<10)有一点误差
      

  3.   

    取日期的年可以用:extract(year from bf2) - extract(month from af2),extract返回的是数字型,可以直接减相差月份用:months_between(bf2,bf1)相差天数直接日期减就可以了,bf2-bf1
      

  4.   

    不好意思,上面写错了点,相差年应该是:extract(year from bf2) - extract(year from af2)
      

  5.   

    修正:
    abs(to_number(to_char(A.af2,'YYYY'))-to_number(to_char(A.af2,'YYYY')))
    改为:
    abs(to_number(to_char(A.af2,'YYYY'))-to_number(to_char(B.bf2,'YYYY')))
      

  6.   

    都是高手,请问一下 duanzilin(寻) :为什么有months_between,没有year_between,有没有day_between
      

  7.   

    year_between可以转换为months_between,day_between可以用两个日期相减的结果来实现,两个日期相减,得到的就是以天为单位的浮点数。
      

  8.   

    相差天数直接减就可以了,相差年也可以用months_between,一年12个月除12就是年了