oracle資料中特殊字元處理

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   sp   資料   

最近資料處理時經常發現有數字中含有大量字元,執行過程報“ORA-01722: invalid number”異常,整理了一下,可以有以下幾種方法去除:

1、replace 用法簡單,寫法較複雜,只能處理已知字元

  With test_table1 As (    Select 1 seq_num, ‘2134?654?ag d35‘ strings From dual          Union All        Select 2 seq_num, ‘651 354a g5 dd21‘ strings From dual    ) Select seq_num, Replace(Replace(Replace(Replace(Replace(strings, ‘?‘, ‘‘), ‘a‘, ‘‘), ‘g‘, ‘‘), ‘d‘, ‘‘), ‘ ‘, ‘‘)   From test_table1;    ---執行結果  1    213465435  2    651354521


2、translate 用法簡單,寫法簡單,只能處理已知字元,字串、待尋找字元,替換字元,均不能為null,否則返回null,字串按尋找順序替換,若無則去除

  With test_table1 As (    Select 1 seq_num, ‘2134?654?ag d35‘ strings From dual     Union All        Select 2 seq_num, ‘651 354a g5 dd21‘ strings From dual    ) Select seq_num, translate(strings, ‘1asdfasg ?‘, ‘1‘)   From test_table1;    ---執行結果  1    213465435  2    651354521


3、regexp_replace Regex 增強型replace 參數多,可根據正則式處理所有字元

  With test_table1 As (    Select 1 seq_num, ‘2134?654?ag d35‘ strings From dual     Union All        Select 2 seq_num, ‘651 354a g5 dd21‘ strings From dual     Union All        Select 3 seq_num, ‘2134654?ag d35‘ strings From dual     Union All        Select 4 seq_num, ‘16?54?aasdgf78as‘ strings From dual     Union All        Select 5 seq_num, ‘[email protected]#$%^&*()~:"+_?><|~8as‘ strings From dual    ) Select seq_num, regexp_replace(strings, ‘[^0-9]‘, ‘‘)    From test_table1;  ---執行結果 1    213465435 2    651354521 3    213465435 4    165478 5    168


註:這些是以前所寫,現轉移到OSC,部落格原文:http://www.cnblogs.com/godsweet/p/3274947.html


oracle資料中特殊字元處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.