oracle 就像在 SQL 中搜索数字列一样

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16186962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:36:41  来源:igfitidea点击:

like search on number column in SQL

sqloracle

提问by user1912935

How do I do a likesearch on a number column in SQL?

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

I want numbers which are like '0.0000%'.

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

I tried with

我试过

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

but in vain.

但徒劳无功。

Please help me

请帮我

回答by Colin 't Hart

Regardless of which DBMS you are using AND assuming you have a valid reason to do this, you have several ways to solve problems like these. I can think of three right now:

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

  1. Convert the number to a string and use a LIKE operator on this:

    select *
    from emp
    where to_char(emp_id) like '123%';
    
  2. Use mathematical operators directly (like Andrey suggests), for example:

    select *
    from table
    where num between 0 and 0.0001;
    
  3. Construct a mathematical expression (actually, this is just another case of method 2), for example:

    select *
    from table
    where abs(num - round(num, 5)) < 0.00001;
    
  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. 构造一个数学表达式(其实这只是方法二的另一种情况),例如:

    select *
    from table
    where abs(num - round(num, 5)) < 0.00001;
    

回答by Andrey Gordeev

Use comparison operators (> and <):

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

select * from table where num > 0 and num < 0.00001

回答by user1912935

select 0.0001*1000 from dual if it is <1 means the 0.0001 has 3 or more zeros. so i did like select * from emp where emp_id*10000<1

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