如何把oracle表中的全角字符转换为半角字符?
a表包含全角字符的字段:address
update a set a.address =(to_single_byte(a.address))
执行,提交,即可。函数解释:
转换成半角函数: to_single_byte(s)
转换成全角函数: to_multi_byte(s)
但是,to_single_byte(s)和to_multi_byte(s)函数发挥作用的前提是数据库字符集包括单字节字符和多字节字符。
oracle数据库安装的是GBK字符集,但是查看表的内码,发现表的数据是用unicode字符集存储的,暂时还未搞明白是怎么回事。。。。。
如果数据库不包含这些字符,需要用repalce()函数,分别手工去替换:
update a t set t.address = replace(t.address,'A','A')
update a t set t.address = replace(t.address,'B','B')
update a t set t.address = replace(t.address,'C','C')
update a t set t.address = replace(t.address,'D','D')
update a t set t.address = replace(t.address,'E','E')
update a t set t.address = replace(t.address,'F','F')
update a t set t.address = replace(t.address,'G','G')
update a t set t.address = replace(t.address,'H','H')
update a t set t.address = replace(t.address,'I','I')
update a t set t.address = replace(t.address,'J','J')
update a t set t.address = replace(t.address,'K','K')
update a t set t.address = replace(t.address,'L','L')
update a t set t.address = replace(t.address,'M','M')
update a t set t.address = replace(t.address,'N','N')
update a t set t.address = replace(t.address,'O','O')
update a t set t.address = replace(t.address,'P','P')
update a t set t.address = replace(t.address,'Q','Q')
update a t set t.address = replace(t.address,'R','R')
update a t set t.address = replace(t.address,'S','S')
update a t set t.address = replace(t.address,'T','T')
update a t set t.address = replace(t.address,'U','U')
update a t set t.address = replace(t.address,'V','V')
update a t set t.address = replace(t.address,'W','W')
update a t set t.address = replace(t.address,'X','X')
update a t set t.address = replace(t.address,'Y','Y')
update a t set t.address = replace(t.address,'Z','Z')
update a t set t.address = replace(t.address,'-','-')
update a t set t.address = replace(t.address,'0','0')
update a t set t.address = replace(t.address,'1','1')
update a t set t.address = replace(t.address,'2','2')
update a t set t.address = replace(t.address,'3','3')
update a t set t.address = replace(t.address,'4','4')
update a t set t.address = replace(t.address,'5','5')
update a t set t.address = replace(t.address,'6','6')
update a t set t.address = replace(t.address,'7','7')
update a t set t.address = replace(t.address,'8','8')
update a t set t.address = replace(t.address,'9','9')
手工写入这些好麻烦,有没有自动化的一点的办法?