select c1,(case
when length(c1)=18 then to_date(substr(c1,7,8),'yyyymmdd')
when length(c1)=15 then to_date(substr(c1,7,6),'rrmmdd')
else ''
end)
from test3

解决方案 »

  1.   

    需要再注意的一个细节就是,如果是18位,取8个,年份是4位,就没有2000年问题。如果是15位的,取6个,年份只有2位,应该注意2000年问题,所以,应该用'rrmmdd'的格式串。
      

  2.   

    create table idcard (id  char(20));
    insert into idcard values('xxx105197806258819');
    insert into idcard values('xxx105780625881');
    SQL> select to_date(decode(length(trim(id)),15,'19'||substr(id,7,6),substr(id,7,8)),'yyyymmdd') from idcard;TO_DATE(DE
    ----------
    25-6月 -78
    25-6月 -78
      

  3.   

    update table_name a set 字段2=(select decode(length(字段1),15,to_date(substr(字段1,7,6),'rrmmdd'),18,to_date(substr(字段1,7,8),'yyyymmdd'),null) from table_name where rowid=a.rowid)