1.1 SQL Operators Overview
1.1 SQL Operators Overview
1.1 SQL Operators Overview
The levels of precedence among the Oracle Database Lite SQL operators from high to low are listed in Table 2-1. Operators listed on the same line have the same level of precedence. Table 2-1 Levels of Precedence of the Oracle Database Lite SQL Operators Precedence Level 1 2 3 SQL Operator Unary + - arithmetic operators, PRIOR operator * / arithmetic operators Binary + - arithmetic operators, || character operators
Visit:
Precedence Level 4 5 6 7
SQL Operator All comparison operators NOT logical operator AND logical operator OR logical operator
Visit:
Oracle Database Lite treats zero-length character strings as nulls. When you concatenate a zero-length character string with another operand the result is always the other operand. A null value can only result from the concatenation of two null strings.
Visit:
Operator >
Example SELECT ENAME "Employee", JOB "Title" FROM EMP WHERE SAL > 3000; SELECT * FROM PRICE WHERE MINPRICE < 30; SELECT * FROM PRICE WHERE MINPRICE >= 20; SELECT ENAME FROM EMP WHERE SAL <= 1500; SELECT * FROM EMP WHERE ENAME IN ('SMITH', 'WARD');
Less than test. Greater than or equal to test. Less than or equal to test. "Equivalent to any member of" test. Equivalent to "=ANY".
ANY/ SOME Compares a value to returned by a query. !=, >, <, <= or >=. the query returns no NOT IN
each value in a list or SELECT * FROM DEPT Must be preceded by =, WHERE LOC = SOME Evaluates to FASLE if ('NEW YORK','DALLAS'); rows. SELECT * FROM DEPT WHERE LOC NOT IN ('NEW YORK', 'DALLAS');
ALL
Compares a value with every value in a list SELECT * FROM emp or returned by a query. Must be preceded by WHERE sal >= ALL (1400, =, !=, >, <, <= or >=. Evaluates to TRUE if 3000); the query returns no rows. SELECT ENAME, JOB FROM EMP WHERE SAL BETWEEN 3000 AND 5000;
[NOT] [Not] greater than or equal to x and less BETWEEN x than or equal to y. and y EXISTS
TRUE if a sub-query returns at least one row. SELECT * FROM EMP WHERE EXISTS (SELECT ENAME FROM EMP WHERE MGR IS NULL);
x [NOT] TRUE if x does [not] match the pattern y. SELECT * FROM EMP LIKE y Within y, the character "%" matches any WHERE ENAME LIKE '%E [ESCAPE z] string of zero or more characters except null. %'; The character "_" matches any single character. Any character following ESCAPE is interpreted literally, useful when y contains a percent (%) or underscore (_). IS [NOT] NULL Tests for nulls. This is the only operator that should be used to test for nulls. SELECT * FROM EMP WHERE COMM IS NOT NULL AND SAL > 1500;
Visit:
OR
Returns all distinct rows selected SELECT * FROM by either query. (SELECT ENAME FROM EMP WHERE JOB = 'CLERK' UNION SELECT ENAME FROM EMP WHERE JOB = 'ANALYST');
UNION ALL
SELECT * FROM (SELECT SAL FROM EMP WHERE JOB = 'CLERK' UNION SELECT SAL FROM EMP WHERE
Visit:
Operator
Description
Returns all distinct rows selected SELECT * FROM orders_list1 by both queries. INTERSECT SELECT * FROM orders_list2
MINUS
Returns all distinct rows selected SELECT * FROM (SELECT SAL by the first query but not the FROM EMP WHERE JOB = second. 'PRESIDENT' MINUS SELECT SAL FROM EMP WHERE JOB = 'MANAGER');
Visit: