3

如何like对 SQL 中的数字列进行搜索?

我想要的数字是like '0.0000%'.

我试过了

select * from emp where emp_id & '' like '123%'
select * from emp where CONVERT(varchar(20), emp_id) like '123%'

但徒劳无功。

请帮我

4

3 回答 3

8

无论您使用哪种 DBMS 并假设您有正当理由这样做,您都有多种方法可以解决此类问题。我现在能想到三个:

  1. 将数字转换为字符串并在此使用 LIKE 运算符:

    select *
    from emp
    where to_char(emp_id) like '123%';
    
  2. 直接使用数学运算符(如 Andrey 建议的那样),例如:

    select *
    from table
    where num between 0 and 0.0001;
    
  3. 构造一个数学表达式(其实这只是方法2的另一种情况),例如:

    select *
    from table
    where abs(num - round(num, 5)) < 0.00001;
    
于 2013-04-24T12:12:10.447 回答
2

使用比较运算符(> 和 <):

select * from table where num > 0 and num < 0.00001
于 2013-04-24T08:24:28.300 回答
0

select 0.0001*1000 from dual 如果 <1 表示 0.0001 有 3 个或更多零。所以我确实喜欢 select * from emp where emp_id*10000<1

于 2013-04-24T11:01:38.613 回答