因为数据库里存在大量 非法格式的时间 varchar2 类型 ,
在按时间查询数据的时间,会发生转换错误。
我怎么才能把,合法格式的时间查询出来,而非法的时间格式的数据忽略呢?select  *
from xxxxx
where xxxxxx ,
 and xxxxxxx,  and  substr(Run_Date,'yyyy-mm-dd') >=to_date('"+tqrq+" 00:00','yyyy-mm-dd hh24:mi')

解决方案 »

  1.   

    你的substr用错了吧给点数据例子
      

  2.   

    写错了:
     And  (To_Char(Sysdate, 'yyyy') - Substr(Run_Date, 1, 4)) Is Not Null  and to_char(sysdate, 'yyyy')-substr(Run_Date,1,4)>="+run_yearbegin);
      

  3.   

    select  * 
    from xxxxx 
    where xxxxxx , 
    and xxxxxxx, 
    and  to_date(Run_Date,'yyyy-mm-dd') is not null ,
    and  to_date(Run_Date,'yyyy-mm-dd') >=to_date(tqrq,'yyyy-mm-dd')****************************************************************************
      select * from  ( select * from x where to_date(Run_Date,'yyyy-mm-dd') is not null ) tb where tb.xxx and tb.xxx and to_date(tb.Run_Date,'yyyy-mm-dd') >=to_date(tqrq,'yyyy-mm-dd')
    *************************************************************************************
    用子查询应该可以解决问题吧?
    还有其他办法吗?
    比如忽略 日期转换异常 只查询能够正常转换的数据。
    我的版本是ORACLE 9I 
      

  4.   

    换个思路想一下 我们不知道非法的数据都是啥格式,但我们知道合法的数据格式,
    筛选一下就OK先把非法的数据筛选一下吧
    WHERE 后加一个条件 把合法的格式保留下来 把非法的格式筛选掉
    SUBSTR、LIKE 等等 
      

  5.   

    select * from x where to_date(Run_Date,'yyyy-mm-dd') is not null  
    这句话查询过程中,还是要报错。
      

  6.   

    select * from 
    ( select * from x where run_date like '____-__-__');