How to check if a value is a number in SQLite

后端 未结 9 2016
-上瘾入骨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:15

    You could try something like this also:

    select * from mytable where printf("%d", field1) = field1;
    

    In case your column is text and contains numeric and string, this might be somewhat helpful in extracting integer data.

    Example:

    CREATE TABLE mytable (field1 text);
    insert into mytable values (1);
    insert into mytable values ('a');
    
    select * from mytable where printf("%d", field1) = field1;
    field1
    ----------
    1
    

提交回复
热议问题