oracle Where子句是否有整数范围?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1137751/
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-18 18:37:34  来源:igfitidea点击:

Is there integer ranges for Where Clause?

sqloracle

提问by zmische

I need to check that result of expression in where clause is in range of Integers.

我需要检查 where 子句中的表达式结果是否在整数范围内。

something lke this:

像这样的东西:

select * from table where (col1 / col2 ) in (1..8). 

With (1..8)representing a range of integers.

(1..8)代表一个整数范围。

I mean that it must be integer, not float. So that I cant use between 1 and 8, because 1.2 will be correct.

我的意思是它必须是整数,而不是浮点数。所以我不能使用between 1 and 8,因为 1.2 是正确的。

回答by Tony Andrews

You can of course do this:

你当然可以这样做:

select * from table where (col1 / col2 ) in (1,2,3,4,5,6,7,8);

or

或者

select * from table where (col1 / col2 ) between 1 and 8
and mod (col1 , col2 ) = 0;

回答by Martin B?gelund

How about

怎么样

select * 
from table
where (col1 / col2 ) BETWEEN 1 AND 8
  and (col1 / col2 ) = FLOOR(col1 / col2 )

This simply checks if the fraction is in the interval, andinteger.

这只是检查分数是否在区间整数中。

回答by Nelson

You could cast it from float to int and use between. (You might want to make a virutal/computed column depending on the query's performance.)

您可以将其从 float 转换为 int 并使用between. (您可能希望根据查询的性能创建虚拟/计算列。)

回答by Bill

To test col1/col2 is an integer, you could Mod them together...

要测试 col1/col2 是一个整数,您可以将它们一起修改...

Where (col1/col2) = (col1\col2) and (col1/col2) between 1 and 8

其中 (col1/col2) = (col1\col2) 和 (col1/col2) 介于 1 和 8 之间

回答by jva

You can use pipeline function to generate integer range.

您可以使用管道函数生成整数范围。

create or replace type my_number_collection is table of number;

create or replace function
  gen_range (p_from in number, p_to in number)
  return my_number_collection
  PIPELINED
  as
  begin
    for i in p_from..p_to loop
      pipe row(i);
    end loop;
    return;
  end;
/

select *
from my_table 
where col1/col2 in (select column_value from table(gen_range(1,8)));