你的这段代码看来,DATE的比较类型上没有问题。

解决方案 »

  1.   

    查询的时候如果不加上
    and hqfhz.begindate <= v_enddate_date   
    and hqfhz.enddate > v_begindate_date;
    的话,就能查询出来呀,所以我觉得是这有问题,关键是
    v_begindate_date := to_date(begindate,'yyyy-mm-dd');
    这个转变对不对,我在test的时候,v_begindate_date变成了 2月2004年19日,是不是有什么关系??
      

  2.   

    to_char(hqfhz.begindate,'yyyymmdd')然后比
      

  3.   

    你的两个日期返回的形式不相同,你要么把v_begindate_date := to_date(begindate,'yyyy-mm-dd');改成v_begindate_date := to_date(begindate,'m月yyyy年dd日');这样,如果客户端session的日期format变了,你也会受到影响。所以建议你这样修改:
    and to_char(hqfhz.begindate,'yyyymmdd') <= to_char(v_enddate_date,'yyyymmdd')
    and to_char(hqfhz.enddate,'yyyymmdd') > to_char(v_begindate_date,'yyyymmdd');
    这样就不会有问题了。
      

  4.   

    同意leborety, 变成字符串比较更加保险!!!
      

  5.   

    select count(*) from  hqfhz,zhdz 
    where zhdz.accountclass ='1'  
     and zhdz.accountatt = deptcode
     and zhdz.accountno = hqfhz.accountno 
     and zhdz.accounttype ='2'
     and hqfhz.begindate <= to_date(2004-03-19,'yyyy-mm-dd')  
     and hqfhz.enddate > to_date(2004-02-19,'yyyy-mm-dd');
    ........--日期之间可以直接比较的.你把上面的一句单独拿出来调试一下,看是否有返回/
      

  6.   

    关键是  
    v_begindate_date  :=  to_date(begindate,'yyyy-mm-dd');  
    这个转变对不对,我在test的时候,v_begindate_date变成了  2月2004年19日,
    -----
    如果hqfhz.enddate,begindate这两个字段是date类型的
    不用考虑转换后日期的形式,都是date类型的就可以进行比较了。    
      

  7.   

    date型的数据在oracle中是以数字形式进行存储的,所以不用考虑转换成date的形式,只要能正确的转换成date型,就可以直接比较大小。建议如果你输入的是字符串(YYYY-MM-DD)的形式,你可以把日期转换整字符串型在进行比较:and to_char(hqfhz.begindate,'YYYY-MM-DD') <= v_enddate_date
    and to_char(hqfhz.enddate,'YYYY-MM-DD') > v_begindate_date;这时一定要注意转换的格式了,一定要使用大写的‘YYYY-MM-DD’才能保证转换成2004-09-15,形式的字符串。
      

  8.   

    我建议你这样做,把数据库中的两个字段先to_char,然后再to_date.即
    to_date(to_char(hqfhz.begindate, 'YYYY-MM-DD'),'YYYY-MM-DD')
    to_date(to_char(hqfhz.enddate , 'YYYY-MM-DD'),'YYYY-MM-DD');
    日期型比较比字符型比较更精确些。