- •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
Cursor Expressions
A CURSOR expression returns a nested cursor. This form of expression is similar to the PL/SQL REF cursor.
CURSOR_expression::=
A nested cursor is implicitly opened when the containing row is fetched from the parent cursor. The nested cursor is closed only when:
The nested cursor is explicitly closed by the user
The parent cursor is reexecuted
The parent cursor is closed
The parent cursor is cancelled
An error arises during fetch on one of its parent cursors (it is closed as part of the clean-up).
Restrictions: The following restrictions apply to the CURSOR expression:
Nested cursors can appear only in a SELECTstatement that is not nested in any other query expression, except when it is a subquery of theCURSORexpression itself.
Nested cursors can appear only in the outermost SELECTlist of the query specification.
Nested cursors cannot appear in views.
You cannot perform BINDandEXECUTEoperations on nested cursors.
Example:
SELECT d.deptno, CURSOR(SELECT e.empno, CURSOR(SELECT p.projnum, p.projname
FROM projects p
WHERE p.empno = e.empno)
FROM TABLE(d.employees) e)
FROM dept d
WHERE d.dno = 605;
Object Access Expressions
This type of expressions are not discussed here.
Decode Expressions
This type of expressions are not discussed here.
Expression List
An expression list is a series of expressions separated by a comma. The entire series is enclosed in parentheses.
expression_list::=
An expression list can contain up to 1000 expressions. Some valid expression lists are:
(10, 20, 40)
('SCOTT', 'BLAKE', 'TAYLOR')
(LENGTH('MOOSE') * 57, -SQRT(144) + 72, 69)
Appendix c. Commentsin sql
Comments within SQL statements do not affect the statement execution, but they may make your application easier for you to read and maintain. You may want to include a comment in a statement that describes the statement's purpose within your application.
A comment can appear between any keywords, parameters, or punctuation marks in a statement. You can include a comment in a statement using either of these means:
Begin the comment with a slash and an asterisk (/*). Proceed with the text of the comment. This text can span multiple lines. End the comment with an asterisk and a slash (*/). The opening and terminating characters need not be separated from the text by a space or a line break.
Begin the comment with -- (two hyphens). Proceed with the text of the comment. This text cannot extend to a new line. End the comment with a line break.
A SQL statement can contain multiple comments of both styles. The text of a comment can contain any printable characters in your database character set.
Example:
These statements contain many comments:
SELECT ename, sal + NVL(comm, 0), job, loc
/* Select all employees whose compensation is
greater than that of Jones.*/
FROM emp, dept
/*The DEPT table is used to get the department name.*/
WHERE emp.deptno = dept.deptno
AND sal + NVL(comm,0) > /* Subquery: */
(SELECT sal + NLV(comm,0)
/* total compensation is sal + comm */
FROM emp
WHERE ename = 'JONES');
SELECT ename, -- select the name
sal + NVL(comm, 0), -- total compensation
job, -- job
loc -- and city containing the office
FROM emp, -- of all employees
dept
WHERE emp.deptno = dept.deptno
AND sal + NVL(comm, 0) > -- whose compensation
-- is greater than
(SELECT sal + NVL(comm,0) -- the compensation
FROM emp
WHERE ename = 'JONES'); -- of Jones.