Oracle 专题
专题目录
您的位置:database > Oracle专题 > Oracle Between子句
Oracle Between子句
作者:--    发布时间:2019-11-20

在本教程中将学习如何使用oracle between运算符来选择值在一个范围内的行数据。

oracle between运算符简介

between运算符允许指定要测试的范围。当使用between运算符为select语句返回的行形成搜索条件时,只返回其值在指定范围内的行。

以下说明between运算符的语法:

expression [ not ] between low and high

在上面的语法中,

  • lowhigh - lowhight指定要测试的范围的下限值和上限值。lowhight值可以是文字或表达式。
  • expression - 是lowhight定义的范围内测试的表达式。 为了能够比较,expressionlowhight的数据类型必须是相同的。
  • and - and运算符充当占位符来分隔lowhight的值。

如果表达式(expression)的值大于或等于low的值,小于或等于hight的值,则between运算符返回true

value >= low and value <= high

not between运算符否定between运算符的结果。

oracle between示例

下面来看看使用oracle between运算符的一些示例。

1. oracle between数值示例

请参阅示例数据库中的以下products表:

以下语句返回标准成本在500600之间的所有产品:

select
    product_name,
    standard_cost
from
    products
where
    standard_cost between 500 and 600
order by
    standard_cost;

在此示例中,我们将标准成本(standard_cost)列中的值与500(含)到600(含)之间的范围进行比较。该查询仅返回标准成本在以下范围之间的产品:

要查询标准成本不在500600之间的产品,请按如下方式将not运算符添加到上述查询中:

select
    product_name,
    standard_cost
from
    products
where
    standard_cost not between 500 and 600
order by
    product_name;

执行上面查询语句,得到以下结果 -

2. oracle between日期示例

我们使用示例数据库中的orders表进行演示:

以下查询语句将返回2016年12月1日至2016年12月31日期间客户的订单:

select
    order_id, customer_id, status, order_date
from
    orders
where
    order_date between date '2016-12-01' and date '2016-12-31'
order by
    order_date;

执行上面查询语句,得到以下结果 -

在本教程中,您已学习如何使用oracle between运算符来选择特定范围内的行数据。


网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册