在Oralce的某一個表中,一個地址字段包含了全角的字符,需要轉換為半角字符,以便進一步處理。
表名:a
包含全角字符的字段:address
編輯表結構,添加一列:address2
在PLSQL中,新建SQL窗口,輸入:update a set a.address2 =(to_single_byte(a.address))
執行,提交,即可。
函數解釋:
轉換成半角函數:
to_single_byte(s)
轉換成
全角
函數:
to_multi_byte(s)
以上這個to_single_byte(s)和to_multi_byte(s)函數發揮作用的前提是數據庫字符集包括單字節字符和多字節字符。
我的另外一台數據庫安裝的是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')
手工寫入這些好麻煩,有沒有自動化的一點的辦法?
如果觉得《oracle全角字符转半角 Oracle 表字段全角字符轉換半角字符辦法》对你有帮助,请点赞、收藏,并留下你的观点哦!