在数据转换中,日期字符串要更新到datetime字段中,如何只转换有效的日期,把无效的日期自动设置为null,如何实现?

解决方案 »

  1.   

    XD,请问什么叫无效的日期?如果要把无效的日期设置为null,用 to_date(null) 就可以了
      

  2.   

      譬如 2007/22/33这样的无效日期。我进行数据转换的时候就不需要了,想把它设置为null,否则日期倒不进去啊。
      

  3.   

    对于这样的情况,写个function,在function中判断是否为日期.
    Create or replace function f_IsDate(p_strDate in varchar2) return date
    is
    begin
       --简化并假设你只有这样的格式.
       return to_date(p_strDate,'yyyy/mm/dd');
    exception
       when others then
          return null;
    end;
    --然后
    update Ytab set Ycol=f_IsDate(Ycol) ;