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

      1. Object Access Expressions

This type of expressions are not discussed here.

      1. Decode Expressions

This type of expressions are not discussed here.

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

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

34

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