Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

Comparison Conditions

Table 5–1 SQL Condition Precedence

Type of Condition

Purpose

 

 

SQL operators are evaluated before SQL

See "Operator Precedence" on page 3-2

conditions

 

 

 

=, !=, <, >, <=, >=,

comparison

 

 

IS [NOT] NULL, LIKE, [NOT]

comparison

BETWEEN, [NOT] IN, EXISTS, IS OF

 

type

 

 

 

NOT

exponentiation, logical negation

 

 

AND

conjunction

 

 

OR

disjunction

 

 

Comparison Conditions

Comparison conditions compare one expression with another. The result of such a comparison can be TRUE, FALSE, or UNKNOWN.

Note: Large objects (LOBs) are not supported in comparison conditions. However, you can use PL/SQL programs for comparisons on CLOB data.

Table 5–2 lists comparison conditions.

Table 5–2

Comparison Conditions

 

Type of

 

 

Condition

Purpose

Example

 

 

 

=

Equality test.

SELECT *

 

 

FROM employees

 

 

WHERE salary = 2500;

!=

^=

< >

¬=

Inequality test. Some forms of the inequality condition may be unavailable on some platforms.

SELECT *

FROM employees

WHERE salary != 2500;

5-4 Oracle9i SQL Reference

Comparison Conditions

Table 5–2

(Cont.) Comparison Conditions

 

Type of

 

 

Condition

Purpose

Example

>

"Greater than" and "less than"

 

tests.

<

 

SELECT * FROM employees WHERE salary > 2500; SELECT * FROM employees WHERE salary < 2500;

>=

"Greater than or equal to" and

 

"less than or equal to" tests.

<=

 

SELECT * FROM employees WHERE salary >= 2500; SELECT * FROM employees WHERE salary <= 2500;

ANY

SOME

ALL

Compares a value to each value in

SELECT * FROM employees

a list or returned by a query. Must

WHERE

salary = ANY

be preceded by =, !=, >, <, <=, >=.

(SELECT salary

Evaluates to FALSE if the query

FROM

employees

returns no rows.

WHERE

department_id = 30);

Compares a value to every value

SELECT * FROM employees

in a list or returned by a query.

WHERE

salary >=

Must be preceded by =, !=, >, <,

ALL (

1400, 3000);

<=, >=.

 

 

Evaluates to TRUE if the query returns no rows.

Simple Comparison Conditions

A simple comparison condition specifies a comparison with expressions or subquery results.

Conditions 5-5

Comparison Conditions

simple_comparison_condition::=

=

!=

^=

<>

expr

expr

>

<

>=

<=

=

,

!=

(

expr

)

(

subquery

)

^=

<>

expression_list::=

,

expr

,

(

expr

)

If you use the lower form of this condition (with multiple expressions to the left of the operator), then you must use the lower form of the expression_list, and the values returned by the subquery must match in number and datatype the expressions in expression_list.

See Also:

"Expression Lists" on page 4-16 for more information about combining expressions

SELECT on page 18-4 for information about subqueries

5-6 Oracle9i SQL Reference

Comparison Conditions

Group Comparison Conditions

A group comparison condition specifies a comparison with any or all members in a list or subquery.

group_comparison_condition::=

=

 

 

 

!=

 

 

 

^=

 

 

 

 

ANY

 

 

<>

 

 

expression_list

expr

SOME

(

)

>

 

 

subquery

 

ALL

 

 

<

 

 

 

>=

 

 

 

<=

 

 

 

 

 

=

 

 

 

,

 

ANY

 

 

 

 

!=

 

 

expression_list

(

expr

)

SOME

(

)

 

 

^=

 

 

subquery

 

 

 

ALL

 

 

 

 

<>

 

 

 

expression_list::=

,

expr

,

(

expr

)

If you use the upper form of this condition (with a single expression to the left of the operator), then you must use the upper form of expression_list. If you use the lower form of this condition (with multiple expressions to the left of the operator), then you must use the lower form of expression_list, and the expressions in each expression_list must match in number and datatype the expressions to the left of the operator.

Conditions 5-7

Соседние файлы в папке Oracle selected docs