Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BD / Labs / English / Lab4-SELECT statement basic features.doc
Скачиваний:
28
Добавлен:
20.02.2016
Размер:
347.14 Кб
Скачать
      1. 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.

      1. 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.

      1. 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

Соседние файлы в папке English