How to check if a value is a number in SQLite

后端 未结 9 2031
-上瘾入骨i
-上瘾入骨i 2020-12-10 14:29

I have a column that contains numbers and other string values (like \"?\", \"???\", etc.)

Is it possible to add an \"is number\" condition to the where clause in SQL

9条回答
  •  余生分开走
    2020-12-10 15:12

    As SQLite and MySQL follow the same syntax and loose datatypes.

    The query below is also possible

    SELECT 
       
     , (
         LENGTH(CAST( AS UNSIGNED))
       )
         =
      CASE WHEN CAST( AS UNSIGNED) = 0
      THEN CAST( AS UNSIGNED)
      ELSE (LENGTH()
      ) END AS is_int;
    

    Note the is BNF you would have the replace those values.

    This answer is based on mine other answer

    Running SQLite demo

提交回复
热议问题