这是我的写法,好象有点麻烦:
select birth_dte, birth_dte + 20 from worker_record
where to_char(birth_dte - 20, 'mmdd') < to_char(sysdate, 'mmdd')
and to_char(birth_dte, 'mmdd') > to_char(sysdate, 'mmdd');有没有更好的?

解决方案 »

  1.   

    粘错了,下面的:
    select * from worker_record
    where to_char(birth_dte - 20, 'mmdd') < to_char(sysdate, 'mmdd')
    and to_char(birth_dte, 'mmdd') > to_char(sysdate, 'mmdd');
      

  2.   

    你这样不是麻烦,而是有问题,如果生日前的20天和生日跨了年度,这样判断就会出错。你的birth_dte是date型的,直接和sysdate比较即可
      

  3.   

    你这样写不是麻烦,而是有问题,如果两个日期跨年度,就会出错。你的birth_dte 是date型的 ,可以这样直接和sysdate比较
      

  4.   

    to: nicholaz:
    怎么比较?
    birth_dte - 20 < sysdate??birth_dte的值比sysdate小很多,没法比较吧!
    你写个语句看看。
      

  5.   

    这样该行了,
    select * from worker_record
    where to_char(birth_dte - 20, 'mmdd') < to_char(sysdate, 'mmdd')
    and to_char(birth_dte, 'mmdd') > to_char(sysdate, 'mmdd')
    and to_char(birth_dte, 'yyyy') = to-char(sysdate, 'yyyy')
      

  6.   

    这样该行了,
    select * from worker_record
    where to_char(birth_dte - 20, 'mmdd') < to_char(sysdate, 'mmdd')
    and to_char(birth_dte, 'mmdd') > to_char(sysdate, 'mmdd')
    and to_char(birth_dte, 'yyyy') = to-char(sysdate, 'yyyy')
      

  7.   

    select * from worker_record where sign(to_char(birth_dte - 20, 'mmdd')-to_char(sysdate,'mmdd'))*sign(to_char(sysdate,'mmdd')-to_char(birth_dte,'mmdd'))=1;
      

  8.   

    select * from  table where to_date('1970-01-01','yyyy-mm-dd')-20 = to_date(sysdate)
      

  9.   

    贴错了,更正
    select * from  table where to_date('1970-01-01','yyyy-mm-dd')-20 = to_date(sysdate,'yyyy-mm-dd')