between用于选择值在一个范围内的行数据,语法“select 字段名 from 表名 where 表达式 [not] between 下限 and 上限”;当该关键字为select语句返回的行形成搜索条件时,只返回其值在指定范围内的行。
本教程操作环境:windows7系统、oracle 11g版、dell g3电脑。
between运算符可以用来在oracle中选择值在一个范围内的行数据。
oracle between运算符语法
between运算符允许指定要测试的范围。当使用between运算符为select语句返回的行形成搜索条件时,只返回其值在指定范围内的行。
以下说明between运算符的语法:
expression [ not ] between low and high
在上面的语法中:
low 和high - low和hight指定要测试的范围的下限值和上限值。low和hight值可以是文字或表达式。
expression - 是low和hight定义的范围内测试的表达式。 为了能够比较,expression,low和hight的数据类型必须是相同的。
and - and运算符充当占位符来分隔low和hight的值。
如果表达式(expression)的值大于或等于low的值,小于或等于hight的值,则between运算符返回true。
value >= low and value <= high
not between运算符否定between运算符的结果。
oracle between示例
下面来看看使用oracle between运算符的一些使用示例。
1. oracle between数值示例
以下方的products表为例:
以下语句返回标准成本在500到600之间的所有产品:
select product_name, standard_costfrom productswhere standard_cost between 500 and 600order by standard_cost;
在此示例中,我们将标准成本(standard_cost)列中的值在500到600之间的范围进行比较筛选。该查询仅返回标准成本在以下范围之间的产品:
要查询标准成本不在500和600之间的产品,请按如下方式将not运算符添加到上述查询中:
select product_name, standard_costfrom productswhere standard_cost not between 500 and 600order by product_name;
2. oracle between日期示例
以下方的orders表为例进行演示:
要查询2016年12月1日至2016年12月31日期间客户的订单,可以使用以下语句:
select order_id, customer_id, status, order_datefrom orderswhere order_date between date '2016-12-01' and date '2016-12-31'order by order_date;
执行语句后,可以得到以下结果:
推荐教程:《oracle教程》
以上就是oracle between的用法是什么的详细内容。