要求修改数据表内容一个字段,字符串,内容为时间把这个字段的时间同意改为 YYYY-MM-DD现有数据样式为
09-01-1
09-1-1
09-1-01
99-01-1
99-1-01
99-1-1
09/1/1
09/01/1
09/1/01
09.1.1
09.01.1
09.1.01基本就是这些,那位大侠有修改的语句,帮帮忙~~~~~~~~~~~~~

解决方案 »

  1.   

    to_char(to_date(translate('./','-'),'yy-mm-dd'),'yyyy-mm-dd')
      

  2.   

    to_char(to_date(translate(原字段,'./','-'),'yy-mm-dd'),'yyyy-mm-dd')
      

  3.   

    楼主可以看下这个
    http://topic.csdn.net/u/20091013/17/9305e6dc-30e6-455d-ad97-a1b4040a6e5c.html
    是关于查询的
      

  4.   

    关于translate 和replace可以看下这个
    http://blog.163.com/agniation4@126/blog/static/968252842009822103851959/
      

  5.   

    ORACLE 正则匹配下
    /* Formatted on 2009/11/11 15:23 (Formatter Plus v4.8.8) */
    SELECT REGEXP_REPLACE ('09/1/1,09.1.01', '[\/\.]', '-') rs
      FROM DUALRS
    --------------
    09-1-1,09-1-01
      

  6.   

    to_char(to_date(translate('./','--'),'yy-mm-dd'),'yyyy-mm-dd')
    这里应该两个减号吧'--'
      

  7.   

    如果就这几种情况,或者已知几种
    可以
    用translate(col1,'./','--')
    若有其他符号可以在'./'里添加,后面的'--'里加上对应的'-'
    若是10g以上的版本可以用
    regexp_replace(col1,'[[:punct:]]','-')
    这么写的话可以替换各种标点符号如果情况更加复杂,写过一个函数,可以看下
    create or replace function fun_date_converted(f_in in varchar2)return varchar2
    as
    v_year varchar2(4);
    v_month varchar2(2);
    v_day varchar2(4);
    v_dot1 number;
    v_dot2 number;
    v_dot3 number;
    v varchar(2);
    l number;
    toolong exception;
    begin
    if f_in is null then return null;
    end if;
    l:=length(f_in);
    for i in 1..l loop
      v_dot1:=i;
      v:=substr(f_in,i,1);
      if v not between '0' and '9' then
        if v_year is null then goto block0;
        else exit;
        end if;
      elsif length(v_year)=3 then v_year:=v_year||v; exit;
      else v_year:=v_year||v;
      end if;
      <<block0>>
      null;
    end loop;
    if v_year is null then return null; end if;
    if length(v_year)=2 then v_year:=case when v_year>'50' then '19' else '20' end||v_year;
    end if;
    if v_dot1=l
       then return v_year||'-1-1';
    end if;for i in v_dot1+1..l loop
      v:=substr(f_in,i,1);
      v_dot2:=i;
      if v not between '0' and '9' then
        if v_month is null then goto block1;
        else exit;
        end if;  elsif v>'2' and v_month='1' then v_dot2:=i-1;exit;  
      elsif v >'1' or length(v_month)=2 then v_month:=v_month||v; exit;
      else v_month:=v_month||v;
      end if;
       <<block1>>
    null;
    end loop;if v_dot2=l or v_month is null
       then return v_year||'-'||nvl(v_month,'1')||'-1';
    end if;for i in v_dot2+1..l loop
      v:=substr(f_in,i,1);
      v_dot3:=i;
      if v not between '0' and '9' then
        if v_day is null then goto block2;
        else exit;
        end if;
      elsif v >'3' or length(v_day)=2 then v_day:=v_day||v; exit;
      else v_day:=v_day||v;
      end if;
       <<block2>>
    null;
    end loop;
    v:=to_char(add_months(to_date(v_year||'-'||v_month||'-1','yyyy-mm-dd'),1)-1,'dd');
    if to_number(v)<to_number(v_day) then
      v_day:=v;
      raise toolong;
    end if;
    if v_dot3<l then 
      for i in v_dot3+1..l loop
        if substr(f_in,i,1) between '0' and '9' then
        raise toolong;
        end if;
      end loop;
    end if;
    return v_year||'-'||v_month||'-'||nvl(v_day,'1');
    exception
      when toolong then
        return to_char(to_number(v_year)+5000)||'-'||v_month||'-'||nvl(v_day,'1');
      when others then 
      return '5000-1-1';end fun_date_converted;传入转换前的字符串,输出转换后的字符串。有问题的地方输出为5000年