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

SERIALLY_REUSABLE Pragma

SERIALLY_REUSABLE Pragma

The pragma SERIALLY_REUSABLE indicates that the package state is needed only for the duration of one call to the server (for example, a PL/SQL anonymous block, an OCI call to the database or a stored procedure call through a database link). After this call, the storage for the package variables can be reused, reducing the memory overhead for long-running sessions. For more information, see Oracle Database Application Developer's Guide - Fundamentals.

Syntax

serially_reusable_pragma

PRAGMA SERIALLY_REUSABLE ;

Keyword and Parameter Description

PRAGMA

Signifies that the statement is a pragma (compiler directive). Pragmas are processed at compile time, not at run time. They do not affect the meaning of a program; they simply convey information to the compiler.

Usage Notes

This pragma is appropriate for packages that declare large temporary work areas that are used once and not needed during subsequent database calls in the same session.

You can mark a bodiless package as serially reusable. If a package has a spec and body, you must mark both. You cannot mark only the body.

The global memory for serially reusable packages is pooled in the System Global Area (SGA), not allocated to individual users in the User Global Area (UGA). That way, the package work area can be reused. When the call to the server ends, the memory is returned to the pool. Each time the package is reused, its public variables are initialized to their default values or to NULL.

Serially reusable packages cannot be accessed from database triggers or other PL/SQL subprograms that are called from SQL statements. If you try, Oracle generates an error.

Examples

The following example creates a serially reusable package:

CREATE PACKAGE pkg1 IS PRAGMA SERIALLY_REUSABLE; num NUMBER := 0;

PROCEDURE init_pkg_state(n NUMBER); PROCEDURE print_pkg_state;

END pkg1;

/

CREATE PACKAGE BODY pkg1 IS PRAGMA SERIALLY_REUSABLE;

PROCEDURE init_pkg_state (n NUMBER) IS BEGIN

pkg1.num := n; END;

PL/SQL Language Elements 13-127

SERIALLY_REUSABLE Pragma

PROCEDURE print_pkg_state IS BEGIN

dbms_output.put_line('Num: ' || pkg1.num); END;

END pkg1;

/

DROP PACKAGE pkg1;

Related Topics

AUTONOMOUS_TRANSACTION Pragma, EXCEPTION_INIT Pragma,

RESTRICT_REFERENCES Pragma

13-128 PL/SQL User's Guide and Reference

SET TRANSACTION Statement

SET TRANSACTION Statement

The SET TRANSACTION statement begins a read-only or read-write transaction, establishes an isolation level, or assigns the current transaction to a specified rollback segment. Read-only transactions are useful for running multiple queries against one or more tables while other users update the same tables. For more information, see "Setting Transaction Properties with SET TRANSACTION" on page 6-32.

Syntax

 

READ

ONLY

 

 

 

 

READ

WRITE

 

NAME

’text’

 

 

 

 

 

SET

TRANSACTION

 

 

SERIALIZABLE

;

 

ISOLATION

LEVEL

 

 

 

 

 

 

 

READ

COMMITTED

 

 

USE

ROLLBACK

SEGMENT

rollback_segment

 

Keyword and Parameter Description

READ ONLY

Establishes the current transaction as read-only, so that subsequent queries see only changes committed before the transaction began. The use of READ ONLY does not affect other users or transactions.

READ WRITE

Establishes the current transaction as read-write. The use of READ WRITE does not affect other users or transactions. If the transaction executes a data manipulation statement, Oracle assigns the transaction to a rollback segment.

ISOLATION LEVEL

Specifies how to handle transactions that modify the database.

SERIALIZABLE: If a serializable transaction tries to execute a SQL data manipulation statement that modifies any table already modified by an uncommitted transaction, the statement fails.

To enable SERIALIZABLE mode, your DBA must set the Oracle initialization parameter COMPATIBLE to 7.3.0 or higher.

READ COMMITTED: If a transaction includes SQL data manipulation statements that require row locks held by another transaction, the statement waits until the row locks are released.

USE ROLLBACK SEGMENT

Assigns the current transaction to the specified rollback segment and establishes the transaction as read-write. You cannot use this parameter with the READ ONLY parameter in the same transaction because read-only transactions do not generate rollback information.

PL/SQL Language Elements 13-129

SET TRANSACTION Statement

NAME

Specifies a name or comment text for the transaction. This is better than using the COMMIT COMMENT feature because the name is available while the transaction is running, making it easier to monitor long-running and in-doubt transactions.

Usage Notes

The SET TRANSACTION statement must be the first SQL statement in the transaction and can appear only once in the transaction.

Example

The following example establishes a read-only transaction:

BEGIN

COMMIT; -- end previous transaction SET TRANSACTION READ ONLY;

FOR person IN (SELECT last_name FROM employees WHERE ROWNUM < 10) LOOP

dbms_output.put_line(person.last_name); END LOOP; dbms_output.put_line('------------------');

FOR dept IN (SELECT department_name FROM departments WHERE ROWNUM < 10) LOOP

dbms_output.put_line(dept.department_name); END LOOP;

COMMIT; -- end read-only transaction END;

/

Related Topics

COMMIT Statement, ROLLBACK Statement, SAVEPOINT Statement

13-130 PL/SQL User's Guide and Reference

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

Мы не исправляем ошибки в тексте (почему?), но будем благодарны, если вы все же напишите об ошибках.

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