Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
37
Добавлен:
16.04.2013
Размер:
5.97 Mб
Скачать

Assigning Values to Records

The keyword ROW is allowed only on the left side of a SET clause. Also, you cannot use ROW with a subquery.

In an UPDATE statement, only one SET clause is allowed if ROW is used.

If the VALUES clause of an INSERT statement contains a record variable, no other variable or value is allowed in the clause.

If the INTO subclause of a RETURNING clause contains a record variable, no other variable or value is allowed in the subclause.

The following are not supported:

Nested record types

Functions that return a record

Record inserts/updates using the EXECUTE IMMEDIATE statement.

Querying Data into Collections of Records

You can use the BULK COLLECT clause with a SELECT INTO or FETCH statement to retrieve a set of rows into a collection of records.

DECLARE

TYPE EmployeeSet IS TABLE OF employees%ROWTYPE;

underpaid EmployeeSet; -- Holds set of rows from EMPLOYEES table.

CURSOR c1 IS SELECT first_name, last_name FROM employees; TYPE NameSet IS TABLE OF c1%ROWTYPE;

some_names NameSet; -- Holds set of partial rows from EMPLOYEES table.

BEGIN

--With one query, we bring all the relevant data into the collection of records. SELECT * BULK COLLECT INTO underpaid FROM employees

WHERE salary < 2500 ORDER BY salary DESC;

--Now we can process the data by examining the collection, or passing it to

--a separate procedure, instead of writing a loop to FETCH each row. dbms_output.put_line(underpaid.COUNT || ' people make less than 2500.'); FOR i IN underpaid.FIRST .. underpaid.LAST

LOOP

dbms_output.put_line(underpaid(i).last_name || ' makes ' || underpaid(i).salary);

END LOOP;

--We can also bring in just some of the table columns.

--Here we get the first and last names of 10 arbitrary employees.

SELECT first_name, last_name BULK COLLECT INTO some_names FROM employees WHERE ROWNUM < 11;

FOR i IN some_names.FIRST .. some_names.LAST LOOP

dbms_output.put_line('Employee = ' || some_names(i).first_name || ' ' ||

some_names(i).last_name); END LOOP;

END;

/

5-38 PL/SQL User's Guide and Reference

Тут вы можете оставить комментарий к выбранному абзацу или сообщить об ошибке.

Оставленные комментарии видны всем.

Соседние файлы в папке Oracle 10g