select *  from Fintaxrate f where f.taxtypeID = 181
                             and f.effectdate =
                                 (select max(effectdate)
                                       from fintaxrate a
                                      where a.taxtypeID = 181
                                        and a.effectdate <=
                                            to_date('2009-12-03',
                                                    'yyyy-MM-dd'))
以上就是这个语句就是从hibernate修改来的,但是使用select max的子语句中查出的数据是null的,因为在hbm.xml文件中effectdate这个字段使用的是非空配置。所以我想问一个各位在这里怎么处理。
另外这个语句我用nvl在很多地方都使用过,都不可以。也就是说这种在sql语句中直接用nvl好像是不生效的,不知道是什么原因,请高手给个解决办法,谢谢

解决方案 »

  1.   

    where f.taxtypeID = 181
                                 and f.effectdate =
                                     (select max(effectdate)
                                           from fintaxrate a
                                          where a.taxtypeID = 181
                                            and a.effectdate <=
                                                to_date('2009-12-03',
                                                        'yyyy-MM-dd'))
    and f.effectdate is not null;
      

  2.   

     用exists
    select *  from Fintaxrate f where f.taxtypeID = 181
                                 and exists
                                     (select 1
                                           from fintaxrate a
                                          where a.taxtypeID = 181
                                            and a.effectdate =f.effectdate 
                                            and a.effectdate <=
                                                to_date('2009-12-03',
                                                        'yyyy-MM-dd'))
      

  3.   

    再修改下:select *  from Fintaxrate f where not  exists 
                                    (select 1 
                                          from fintaxrate a 
                                          where a.taxtypeID = 181 
                                            and a.effectdate < f.effectdate 
                                            and a.effectdate <= 
                                                to_date('2009-12-03', 
                                                        'yyyy-MM-dd'))