Oracle8i SQL ReferenceRelease 2 (8.1.6)A76989-01

Operators, 7 of 10

## Logical Operators

A logical operator combines the results of two component conditions to produce a single result based on them or to invert the result of a single condition. Table 3-5 lists logical operators.

##### Table 3-5 Logical Operators
Operator  Function  Example
```NOT
```

Returns `TRUE` if the following condition is `FALSE`. Returns `FALSE` if it is `TRUE`. If it is `UNKNOWN`, it remains `UNKNOWN`

```SELECT *
FROM emp
WHERE NOT (job IS NULL);
SELECT *
FROM emp
WHERE NOT
(sal BETWEEN 1000 AND 2000);
```

```AND
```

Returns `TRUE` if both component conditions are `TRUE`. Returns `FALSE` if either is `FALSE`. Otherwise returns `UNKNOWN`

```SELECT *
FROM emp
WHERE job = 'CLERK'
AND deptno = 10;
```

```OR
```

Returns `TRUE` if either component condition is `TRUE`. Returns `FALSE` if both are `FALSE`. Otherwise returns `UNKNOWN`

```SELECT *
FROM emp
WHERE job = 'CLERK'
OR deptno = 10;
```

For example, in the `WHERE` clause of the following `SELECT` statement, the `AND` logical operator is used to ensure that only those hired before 1984 and earning more than \$1000 a month are returned:

```SELECT *
FROM emp
WHERE hiredate < TO_DATE('01-JAN-1984', 'DD-MON-YYYY')
AND sal > 1000;
```

### NOT Operator

Table 3-6 shows the result of applying the `NOT` operator to a condition.

##### Table 3-6 NOT Truth Table

TRUE

FALSE

UNKNOWN

NOT

`FALSE`

`TRUE`

`UNKNOWN`

### AND Operator

Table 3-7 shows the results of combining two expressions with `AND`.

##### Table 3-7 AND Truth Table
 AND TRUE FALSE UNKNOWN TRUE `TRUE` `FALSE` `UNKNOWN` FALSE `FALSE` `FALSE` `FALSE` UNKNOWN `UNKNOWN` `FALSE` `UNKNOWN`

### OR Operator

Table 3-8 shows the results of combining two expressions with `OR`.

##### Table 3-8 OR Truth Table
 OR TRUE FALSE UNKNOWN TRUE `TRUE` `TRUE` `TRUE` FALSE `TRUE` `FALSE` `UNKNOWN` UNKNOWN `TRUE` `UNKNOWN` `UNKNOWN`