Oracle9i SQL Reference
Release 1 (9.0.1)

Part Number A90125-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

Conditions, 2 of 11


About SQL Conditions

A condition combines one or more expressions and logical operators and returns a value of TRUE, FALSE, or unknown.

Types of Conditions

Conditions can have several forms, as shown in the following syntax.

condition::=


Text description of conditions8a.gif follows
Text description of condition


Note:

If you have installed Oracle Text, you can use the built-in conditions that are part of that product, including CONTAINS, CATSEARCH, and MATCHES. For more information on these Oracle Text elements, please refer to Oracle Text Reference


The sections that follow describe the various forms of conditions. You must use appropriate condition syntax whenever condition appears in SQL statements.

You can use a condition in the WHERE clause of these statements:

You can use a condition in any of these clauses of the SELECT statement:

A condition could be said to be of the "logical" datatype, although Oracle does not formally support such a datatype.

The following simple condition always evaluates to TRUE:

1 = 1 

The following more complex condition adds the sal value to the comm value (substituting the value 0 for null) and determines whether the sum is greater than the number constant 2500:

NVL(salary, 0) + NVL(salary + (salary*commission_pct, 0) > 25000)

Logical conditions can combine multiple conditions into a single condition. For example, you can use the AND condition to combine two conditions:

(1 = 1) AND (5 < 7) 

Here are some valid conditions:

name = 'SMITH' 
employees.department_id = departments.department_id 
hire_date > '01-JAN-88' 
job_id IN ('SA_MAN', 'SA_REP') 
salary BETWEEN 5000 AND 10000
commission_pct IS NULL AND salary = 2100

See Also:

The description of each statement in Chapter 8 through Chapter 17 for the restrictions on the conditions in that statement 

Condition Precedence

Precedence is the order in which Oracle evaluates different conditions in the same expression. When evaluating an expression containing multiple conditions, Oracle evaluates conditions with higher precedence before evaluating those with lower precedence. Oracle evaluates conditions with equal precedence from left to right within an expression.

Table 5-1 lists the levels of precedence among SQL condition from high to low. Conditions listed on the same line have the same precedence. As the table indicates, Oracle evaluates operators before conditions.

Table 5-1 SQL Condition Precedence  
Condition  Purpose 

SQL operators 

See "Operator Precedence" 

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

comparison 

IS [NOT] NULL, LIKE, [NOT] BETWEEN, [NOT] IN, EXISTS, IS OF type 

comparison 

NOT 

exponentiation, logical negation 

AND 

conjunction 

OR 

disjunction 


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback