Oracle判斷是否為數字或數字型字串(sqlserver isnumeric)

來源:互聯網
上載者:User

需求:

如果欄位值不是數字或者數字型字串,把該欄位值update成'' 

1.函數法(不能批量,捨棄):

[sql]
  1. create   or   replace   function   isNumber(p_in   varchar2)   return   boolean   as   
  2.         i   number;   
  3. begin   
  4.         i:=to_number(p_in);   
  5.         return   true;   
  6. exception         
  7.         when   others   then     
  8.               return   false;   
  9. end   ;   

但是這個好像只能一個個判斷,不能批量。

2.

[sql]
  1. SQL> select   nvl2(translate('333', '\1234567890 ', '\'), 'is   characters ', 'is   number ')   from   dual;  
  2.   
  3. NVL2(TRANSLATE('333','\1234567  
  4. ------------------------------   
  5. is   number  
  6.   
  7. SQL> select   nvl2(translate(333, '\1234567890 ', '\'), 'is   characters', 'is   number')   from   dual;  
  8.   
  9. NVL2(TRANSLATE(333,'\123456789  
  10. ------------------------------   
  11. is   number  
  12.   
  13. SQL> select   nvl2(translate('aaaaa', '\1234567890 ', '\'), 'is   characters', 'is   number')   from   dual;  
  14.   
  15. NVL2(TRANSLATE('AAAAA','\12345  
  16. ------------------------------   
  17. is   characters  
  18.   
  19. SQL>   

3.據說要批量,可以這樣先查出來,沒有試過:

[sql]
  1. select   decode(nvl2(translate(column, '\1234567890 ', '\'), '0', '1') ,'1',column,'')  from   dual;  

我寫的:

[sql]
  1. Update T_87_Mtbuf Set SpCode='' Where  nvl2(translate(SpCode, '\1234567890 ', '\'), 'is   characters', 'is   number ')='is   characters';  

補充一點:

to_number(...)中只能接受數字如122或數字型字串'122',接受'aaa'會報錯“無效字元”。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.