- •Laboratory work 4
- •Description and examples
- •The Building Blocks of Data Retrieval: select and from clauses
- •The select clause
- •The froMclause
- •The where clause
- •Use of simple conditions
- •Use of comparison operators
- •Logical operators.
- •Column expressions in where clause
- •Special operators
- •Operator in
- •Operator between
- •Operator like
- •Operators is null and is not null.
- •Oracle Lab tasks
- •Вариант 1
- •Вариант 2
- •Вариант 3
- •Вариант 4
- •Вариант 5
- •Вариант 6
- •Вариант 7
- •Вариант 8
- •Вариант 9
- •Вариант 10
- •Вариант 11
- •Вариант 12
- •Вариант 13
- •Вариант 14
- •Вариант 15
- •Вариант 16
- •Вариант 17
- •Вариант 18
- •Control questions
- •Appendices
- •Appendix a. Sql Oracle operators
- •Unary and binary operators
- •Precedence
- •Arithmetic Operators
- •Concatenation Operator
- •Comparison Operators
- •Logical Operators
- •Set Operators
- •Appendix b. Expressions
- •Simple Expressions
- •Cursor Expressions
- •Object Access Expressions
- •Decode Expressions
- •Expression List
- •Appendix c. Commentsin sql
Comparison Operators
Comparison operators compare one expression with another. The result of such a comparison can be TRUE, FALSE, or UNKNOWN. For information on conditions, see Appendix A of Lab2. The table bellow lists SQL comparison operators.
Operator |
Purpose |
Example |
= |
Equality test |
SELECT * FROM DEPARTMENT WHERE Fund = 15000; |
!=, ^=, <>, ¬= |
Inequality test. |
SELECT * FROM DEPARTMENT WHERE Fund != 15000; |
>, < |
"Greater than" and "less than" tests |
SELECT * FROM FACULTY SELECT * FROM FACULTY WHERE Fund > 1500; WHERE Fund < 1500; |
>=, <= |
"Greater than or equal to" and "less than or equal to" tests |
SELECT * FROM FACULTY SELECT * FROM FACULTY WHERE Fund >= 1500; WHERE Fund <= 1500; |
IN |
"Equal to any member of" test. Equivalent to "= ANY" |
SELECT Name, Post FROM TEACHER WHERE Post IN ('professor', 'assistant'); |
NOT IN |
Equivalent to !=ALL. Evaluates to FALSE if any member of the set is NULL |
SELECT * FROM FACULTY WHERE Fund NOT IN (SELECT Fund FROM FACULTY WHERE Building IN ('3','5')}; |
ANY, SOME |
Compares a value to each value in a list or returned by a query. Must be preceded by =, !=, >, <, <=, >=. Evaluates to FALSE if the query returns no rows. |
SELECT * FROM TEACHER WHERE Salary = ANY (SELECT Salary FROM TEACHER WHERE Post = 'professor'); |
ALL |
Compares a value to every value in a list or returned by a query. Must be preceded by =, !=, >, <, <=, >=. Evaluates to TRUE if the query returns no rows. |
SELECT * FROM TEACHER WHERE Salary >= ALL (350, 400, 420); |
[NOT] BETWEEN x AND y |
[Not] greater than or equal to x and less than or equal to y. |
SELECT * FROM TEACHER WHERE Salary BETWEEN 350 AND 420; |
EXISTS |
TRUE if a subquery returns at least one row. It is unary operator. |
SELECT Name FROM TEACHER WHERE EXISTS (SELECT * FROM LECTURE WHERE LECTURE.TchNo=TEACHER. TchNo); |
x [NOT] LIKE y [ESCAPE ‘z’] |
TRUE if x does [not] match the pattern y. Within y, the character "%" matches any string of zero or more characters except null. The character "_" matches any single character. Any character, excepting percent (%) and underbar (_) may follow ESCAPE. A wildcard character is treated as a literal if preceded by the character designated as the escape character. |
SELECT Name FROM TEACHER WHERE Name LIKE 'Ив%'; |
IS [NOT] NULL |
Tests for nulls. This is the only operator that you should use to test for nulls. |
SELECT Name, Tel FROM TEACHER WHERE Commission IS NULL; |
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 that follows lists logical operators.
Operator |
Purpose |
Example |
NOT |
Unary operator. Returns TRUE if the condition is FALSE. Returns FALSE if it is TRUE. If it isUNKNOWN, it remainsUNKNOWN. |
SELECT * FROM TEACHER WHERE NOT (Salary BETWEEN 450 AND 500); |
AND |
Binary operator. Returns TRUE if both component conditions are TRUE. Returns FALSE if either is FALSE. Otherwise returnsUNKNOWN. |
SELECT * FROM TEACHER WHERE Hiredate < TO_DATE('01-JAN-2000', 'DD-MMM-YYYY') AND Salary > 500; |
OR |
Binary operator. Returns TRUE if either component condition is TRUE. Returns FALSE if both are FALSE. Otherwise returnsUNKNOWN. |
SELECT * FROM TEACHER WHERE Post = 'assistant' AND Salary > 500; |
Logical operators have the following meaning:
|
|
|