DB2- How to check if varchar field value has integers

后端 未结 7 903
借酒劲吻你
借酒劲吻你 2020-12-10 02:58

Is there an inbuilt DB2 function or any query to check if the character i have is a number? (I cannot use user defined functions)

7条回答
  •  我在风中等你
    2020-12-10 03:32

    if you version of db2 can use regexp_like you can do it:

    number with "." as decimal symbol:

     select *      from yourtable                            
     where REGEXP_LIKE(trim(yourzone) , '^\d+(\.\d*)?$')
    

    number with "," as decimal symbol:

     select *      from yourtable                            
     where REGEXP_LIKE(trim(yourzone) , '^\d+(\,\d*)?$') 
    

    number without decimal symbol ( integer only, your ask)

     select *      from yourtable                  
     where REGEXP_LIKE(trim(yourzone) , '^\d+$')
    

提交回复
热议问题