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

Choosing Between Native Dynamic SQL and the DBMS_SQL Package

Here, the same cursor is reused for different values of the bind my_deptno, improving performance and scalabilty.

Native Dynamic SQL Supports User-Defined Types

Native dynamic SQL supports all of the types supported by static SQL in PL/SQL, including user-defined types such as user-defined objects, collections, and REFs. The DBMS_SQL package does not support these user-defined types.

Note: The DBMS_SQL package provides limited support for arrays. See the PL/SQL Packages and Types Reference for information.

Native Dynamic SQL Supports Fetching Into Records

Native dynamic SQL and static SQL both support fetching into records, but the DBMS_SQL package does not. With native dynamic SQL, the rows resulting from a query can be directly fetched into PL/SQL records.

In the following example, the rows from a query are fetched into the emp_rec record:

DECLARE

TYPE EmpCurTyp IS REF CURSOR; c EmpCurTyp;

emp_rec emp%ROWTYPE; stmt_str VARCHAR2(200); e_job emp.job%TYPE;

BEGIN

stmt_str := 'SELECT * FROM emp WHERE job = :1'; -- in a multi-row query

OPEN c FOR stmt_str USING 'MANAGER'; LOOP

FETCH c INTO emp_rec; EXIT WHEN c%NOTFOUND;

END LOOP; CLOSE c;

-- in a single-row query

EXECUTE IMMEDIATE stmt_str INTO emp_rec USING 'PRESIDENT';

END;

/

Coding Dynamic SQL Statements 6-15

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