Operator
|
Purpose
|
Example
|
+ -
|
Denotes a positive or negative expression. These are unary operators.
|
SELECT * FROM emp WHERE comm = -1
|
* /
|
Multiplies, divides. These are binary operators.
|
UPDATE emp SET sal = sal + sal * 0.10
|
+ -
|
Adds, subtracts. These are binary operators.
|
SELECT sal + comm FROM emp WHERE empno > 100
|
Operator
|
Purpose
|
Example
|
||
|
Concatenates character strings. The operator always returns a VARCHAR.
|
SELECT 'Name is' || ename FROM emp
|
Operator
|
Purpose
|
Example
|
=
|
Equality test.
|
SELECT * FROM emp WHERE sal = 1500
|
!= or <>
|
Inequality test.
|
SELECT * FROM emp WHERE sal != 1500
|
> and <
|
“Greater than" and "less than" tests.
|
SELECT * FROM emp WHERE sal > 1500
SELECT * FROM emp WHERE sal < 1500 |
>= and <=
|
“Greater than or equal to" and "less than or equal to" tests.
|
SELECT * FROM emp WHERE sal >= 1500
SELECT * FROM emp WHERE sal <= 1500 |
[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 |
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.SELECT * FROM emp WHERE ENAME LIKE 'JOE\_JOHN' ESCAPE '\'This matches only records with name ’JOE_JOHN’.
|
Operator
|
Purpose
|
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
|
Precedence
|
Operator
|
1
|
+ (Positive), - (Negative)
|
2
|
*(Multiply), / (Division)
|
3
|
+ (Add), - (Subtract)
|
4
|
|| (Concatenate)
|
5
|
=, >, <, >=, <=, <>, != (Comparison operators)
|
6
|
NOT, IN, LIKE
|
7
|
AND
|
8
|
OR
|