现在的位置: 首页 > 综合 > 正文

oracle 全角转半角

2014年08月01日 ⁄ 综合 ⁄ 共 777字 ⁄ 字号 评论关闭

       有这么一个需求,一个时间字段在当初设计的时候设计成varchar2,现在要该回成date,但发现里面的数据五花八门,其中有一类数据就是全角,要改为半角,不然转换为报错。

SQL> drop table test purge;

SQL> create table test (record_time varchar2(100));

表已创建。

SQL> insert into test values('2006-7-25 14:00');

已创建 1 行。

SQL> insert into test values('2010-7-25 15:00');

已创建 1 行。

SQL> insert into test values('2007-7-25 14:00');

已创建 1 行。

SQL> insert into test values('2008-7-25 15:00');

已创建 1 行。

SQL> commit;

提交完成。

SQL> select to_date(record_time,'yyyy-MM-dd HH24:mi') from test;
ERROR:
ORA-01858: 在要求输入数字处找到非数字字符

未选定行

SQL> update test
       set record_time = to_single_byte(record_time)
     where regexp_like(record_time, '1|2|3|4|5|6|7|8|9|0|:');

已更新2行。

SQL> commit;

提交完成。

SQL> select to_date(record_time,'yyyy-MM-dd HH24:mi') from test;

TO_DATE(RECORD
--------------
25-7月 -06
25-7月 -10
25-7月 -07
25-7月 -08

 

附:

to_single_byte(c)转换成半角
to_multi_byte(c)转换成全角

抱歉!评论已关闭.