- •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
Precedence
Precedence is the order in which SQL Oracle evaluates different operators in the same expression. When evaluating an expression containing multiple operators, Oracle evaluates operators with higher precedence before evaluating those with lower precedence. SQL Oracle evaluates operators with equal precedence from left to right within an expression.
Table bellow lists the levels of precedence among SQL operators from high to low. Operators listed on the same line have the same precedence.
|
Operator |
Operation |
|
+, - |
unary plus and minus |
|
*, / |
multiplication,division |
|
+, -, || |
addition,subtraction,concatenation |
|
=, !=, <, >, <=, >=, IS NULL, LIKE, BETWEEN, IN |
comparison |
|
NOT |
logical negation |
|
AND |
conjunction |
|
OR |
disjunction |
You can use parentheses in an expression to override operator precedence. Oracle evaluates expressions inside parentheses before evaluating those outside.
SQL also supports set operators (UNION, UNION ALL, INTERSECT, and MINUS), which combine sets of rows returned by queries, rather than individual data items. All set operators have equal precedence.
Arithmetic Operators
You can use an arithmetic operator in an expression to negate, add, subtract, multiply, and divide numeric values. The result of the operation is also a numeric value. Some of these operators are also used in date arithmetic. Table bellow lists arithmetic operators.
|
Operator |
Purpose |
Example |
|
+, - |
Denotes a positive or negative expression. These are unary operators. |
SELECT * FROM orders SELECT * FROM TEACHER WHERE qtysold = -1; WHERE -Salary < 0; |
|
*, / |
Binary multiplication and division. |
UPDATE TEACHER SET Salary = Salary * 1.1; |
|
+, - |
Binary addition and subtraction |
SELECT Salary + Commission FROM TEACHER WHERE SYSDATE - Hiredate > 365; |
Do not use two consecutive minus signs (--) in arithmetic expressions to indicate double negation or the subtraction of a negative value. The characters -- are used to begin comments within SQL statements (See Appendix C). You should separate consecutive minus signs with a space or a parenthesis.
Concatenation Operator
The concatenation operator manipulates character strings. Table bellow describes concatenation operator.
|
Operator |
Purpose |
Example |
|
|| |
Concatenates character strings. |
SELECT 'Name is ' || Name FROM FACULTY; |
The result of concatenating two character strings is another character string. If both character strings are of datatype CHAR, the result has datatype CHAR and is limited to 2000 characters. If either string is of datatype VARCHAR2, the result has datatype VARCHAR2 and is limited to 4000 characters. Trailing blanks in character strings are preserved by concatenation, regardless of the strings' datatypes.
Oracle provides the CONCAT character function as an alternative to the vertical bar operator.
Although Oracle treats zero-length character strings as nulls, concatenating a zero-length character string with another operand always results in the other operand, so null can result only from the concatenation of two null strings. However, this may not continue to be true in future versions of Oracle. To concatenate an expression that might be null, use the NVL function to explicitly convert the expression to a zero-length
