Comparison Operators
- Last Updated: June 14, 2020
- 1 minute read
- DataDirect Connectors
- JDBC
- Oracle Service Cloud 5.1
- Documentation
Comparison operators compare one expression to another. The result of such a comparison can be TRUE, FALSE, or UNKNOWN (if one of the operands is NULL). The Oracle Service Cloud driver considers the UNKNOWN result as FALSE.
The following table lists the supported comparison operators.
| Operator | Purpose | Example |
|---|---|---|
| = | Equality test. |
SELECT * FROM emp WHERE sal = 1500
|
| !=<> | Inequality test. |
SELECT * FROM emp WHERE sal != 1500
|
| >< | “Greater than" and "less than" tests. |
SELECT * FROM emp WHERE sal > 1500
SELECT * FROM emp WHERE sal < 1500
|
| >=<= | “Greater than or equal to" and "less than or equal to" tests. |
SELECT * FROM emp WHERE sal >= 1500
SELECT * FROM emp WHERE sal <= 1500
|
| ESCAPE clause in LIKE operator LIKE ’pattern string’ ESCAPE ’c’ |
The Escape clause is supported
in the LIKE predicate to indicate the escape character. Escape characters are used
in the pattern string to indicate that any wildcard character that is after the
escape character in the pattern string should be treated as a regular character. The default escape character is backslash (\). |
SELECT * FROM emp WHERE ENAME LIKE
'J%\_%' ESCAPE '\'This matches all records with names that start with letter 'J' and have the '_' character in them.
This matches only records with name ’JOE_JOHN’. |
| [NOT] IN | “Equal to any member of" test. |
SELECT * FROM emp WHERE job IN ('CLERK','ANALYST')
SELECT * FROM emp WHERE sal IN (SELECT sal FROM emp WHERE deptno = 30)
|
| [NOT] BETWEEN x AND y | "Greater than or equal to x" and "less than or equal to y." |
SELECT * FROM emp WHERE sal BETWEEN 2000 AND 3000
|
| EXISTS | Tests for existence of rows in a subquery. |
SELECT empno, ename, deptno FROM emp e WHERE EXISTS (SELECT deptno FROM dept WHERE e.deptno = dept.deptno)
|
| IS [NOT] NULL | Tests whether the value of the column or expression is NULL. |
SELECT * FROM emp WHERE ename IS NOT NULL
SELECT * FROM emp WHERE ename IS NULL
|