Previous Topic: PredicatesNext Topic: Quantified Predicate


Basic Predicate

A basic predicate is used to compare two values. The format of a basic predicate is:

Following is the syntax diagram for a basic predicate:

Note: The following are CA Datacom/DB extensions:

►►─ expression ─┬─ = ─────┬─┬─ expression ──┬─────────────────────────────────►◄
                ├─ < ─────┤ └─ (subselect) ─┘
                ├─ > ─────┤
                ├─ <> ────┤
                ├─ <= ────┤
                ├─ >= ────┤
                ├─ ¬= ────┤
                ├─ ¬< ────┤
                └─ ¬> ────┘

Description

expression

Specify an expression. For more information about expressions, see Expressions.

(subselect)

Specify a subselect. The subselect must be enclosed by parentheses. For more information about the subselect see Subselect.

The result of the comparison is either true or false. The following table shows the results for each comparison operator when comparing the values x and y.

Predicate

Is true only if...

x = y

x is equal to y

x < y

x is less than y

x > y

x is greater than y

x <> y

x is not equal to y

x <= y

x is less than or equal to y

x >= y

x is greater than or equal to y

x ¬= y

x is not equal to y

x ¬< y

x is not less than y

x ¬> y

x is not greater than y

The ¬=, ¬< and ¬> comparison operators are CA Datacom/DB extensions to SQL.

Examples

Some examples of basic predicates are:

Example 1: This example specifies that the employee number must be equal to the literal value 671.

 EMPNO = '671'

Example 2: This example specifies that the salary must be less than $20,000.

 SALARY < 20000

Example 3: This example specifies that the quantity must not be equal to the value of the host-variable, VAR1.

 QUANTITY <> :VAR1

Example 4: This example specifies that the salary must be greater than the average salary for all employees.

 SALARY > (SELECT AVG(SALARY)
           FROM EMP)