Oracle® Database PL/SQL Packages and Types Reference 11g Release 2 (11.2) Part Number E10577-03 |
|
|
View PDF |
The DBMS_STREAMS_HANDLER_ADM
package, one of a set of Oracle Streams packages, provides interfaces to manage statement DML handlers.
This chapter contains the following topics:
Using DBMS_STREAMS_HANDLER_ADM
Overview
Views
Operational Notes
This section contains topics that relate to using the DBMS_STREAMS_HANDLER_ADM
package.
A statement DML handler runs one or more data manipulation language (DML) statements on row logical change records (row LCRs) that are dequeued by an apply process. A single statement DML handler can include multiple statements, and you control the execution order of the statements.
Statement DML handlers are similar to procedure DML handlers for apply processes. Both statement DML handlers and procedure DML handlers provide custom processing of row changes that are encapsulated in row LCRs. Statement DML handlers and procedure DML handlers both run when an apply process dequeues a row LCR. However, statement DML handlers have the following advantages over procedure DML handlers:
Statement DML handlers typically perform better than procedure DML handlers because statement DML handlers do not require PL/SQL processing.
The syntax for statement DML handlers is same as DML syntax. Statement DML handlers do not require PL/SQL programming. Procedure DML handlers require PL/SQL programming.
Statement DML handlers do not require the manipulation of ANYDATA
values to access the information in row LCRs. Typically, procedure DML handlers must manipulate ANYDATA
values.
A statement DML handler can co-exist with an error handler for same operation on the same database object. In contrast, you cannot specify both a procedure DML handler and an error handler for the same operation on the same database object.
Note:
You can specify multiple statement DML handlers for the same operation on the database object. In this case, the statement DML handlers can execute in any order, and each statement DML handler receives a copy of the original row LCR that was dequeued by the apply process.The DBMS_STREAMS_HANDLER_ADM
package uses the views listed in the Oracle Database Reference.
DBA_APPLY_DML_HANDLERS
DBA_STREAMS_STMTS
DBA_STREAMS_STMT_HANDLERS
The following sections contain operational notes about the DBMS_STREAMS_HANDLER_ADM
package:
Each statement in a statement DML handler has a unique execution sequence number. When a statement DML handler is invoked, it executes its statements in order from the statement with the lowest execution sequence number to the statement with the highest execution sequence number.
You can use statement DML handlers for any valid DML operation on a row logical change record (row LCR). For example, a statement DML handler can audit the DML changes made to a table.
The following SQL statements are supported in statement DML handlers:
INSERT
UPDATE
DELETE
MERGE
In addition, define variables are not supported in the SQL statements in a statement DML handler.
However, the SQL statements in a statement DML handler can include calls to member subprograms for the row LCR type (LCR$_ROW_RECORD
), such as ADD_COLUMN
, DELETE_COLUMN
, KEEP_COLUMNS
, and RENAME_COLUMN
.
Note:
A statement DML handler cannot modify the value of a column in a row LCR.See Also:
"LCR$_ROW_RECORD Type"Statements in statement DML handlers can contain the row LCR column attributes described in Table 144-1.
Table 144-1 Row LCR Column Attributes
Attribute | Description |
---|---|
|
Returns the new column value in a row LCR. If the new value does not exist, then this attribute returns the old value. |
|
Returns Returns |
|
Returns the new column value in a row LCR. If the new value does not exist, then this attribute returns |
|
Returns the old column value in a row LCR. |
|
Returns Returns |
Specify these attributes in the following way in a statement:
:attribute.column_name
For example, to specify the new_only
attribute for the salary
column, enter the following in a statement:
:new_only.salary
Statements in statement DML handlers can contain the row LCR attributes described in Table 144-2.
Table 144-2 Row LCR Attributes
Attribute | Description |
---|---|
|
Returns the type of DML statement that produced the change, either |
|
Returns the commit system change number (SCN) of the transaction to which the LCR belongs. |
|
Returns the minimal database compatibility required to support the LCR. |
|
Returns the instance number of the database instance that made the change that is encapsulated in the LCR. Typically, the instance number is relevant in an Oracle Real Application Clusters (Oracle RAC) configuration. |
|
Returns the schema name that contains the table with the changed row. |
|
Returns the name of the table that contains the changed row. |
|
Returns the SCN at the time when the change was made. |
|
Returns the name of the source database where the row change occurred. |
|
Returns the time when the change in an LCR captured by a capture process was generated in the redo log of the source database, or the time when a persistent LCR was created. |
|
Returns a raw tag that can be used to track the LCR. |
|
Returns the identifier of the transaction in which the DML statement was run. |
Specify these attributes in the following way in a statement:
:attribute_name
For example, to specify the source_database_name
attribute for a row LCR, enter the following in a statement:
:source_database_name
Statements in statement DML handlers can contain the row LCR extra attributes described in Table 144-3.
Table 144-3 Row LCR Extra Attributes
Attribute | Description |
---|---|
|
Returns the rowid of the row changed in a row LCR. |
|
Returns the serial number of the session that performed the change captured in the LCR. |
|
Returns the identifier of the session that performed the change captured in the LCR. |
|
Returns the thread number of the instance in which the change captured in the LCR was performed. Typically, the thread number is relevant only in an Oracle RAC configuration. |
|
Returns the name of the transaction that includes the LCR. |
|
Returns the name of the current user who performed the change captured in the LCR. |
Specify these attributes in the following way in a statement:
:extra_attribute.attribute_name
For example, to specify the row_id
extra attribute for a row LCR, enter the following in a statement:
:extra_attribute.row_id
A statement in a statement DML handler can include a call to the EXECUTE
member procedure for row LCRs. The EXECUTE
member procedure executes the row LCR under the security domain of the current user.
A statement that runs the EXECUTE
member procedure can be placed anywhere in the execution sequence order of the statement DML handler. It is not necessary to execute a row LCR unless the goal is to apply the changes in the row LCR to a table in addition to performing any other SQL statements in the statement DML handler.
When you call the EXECUTE
member procedure in a statement, the conflict_resolution
parameter controls whether any conflict resolution defined for the table using the SET_UPDATE_CONFLICT_HANDLER
procedure in the DBMS_APPLY_ADM
package is used to resolve conflicts resulting from the execution of the LCR:
:lcr.execute TRUE|FALSE
A TRUE
argument indicates that conflict resolution is used. A FALSE
argument indicates that conflict resolution is not used.
For example, to use conflict resolution, enter the following in a statement:
:lcr.execute TRUE
An error is raised if this parameter is not specified or is set to NULL
.
Table 144-4 DBMS_STREAMS_HANDLER_ADM Package Subprograms
Subprogram | Description |
---|---|
Adds a statement to a statement DML handler |
|
Creates a statement DML handler |
|
Drops a statement DML handler |
|
Removes a statement from a statement DML handler |
Note:
The subprograms in this package do not commit.This procedure adds a statement to a statement DML handler.
Syntax
DBMS_STREAMS_HANDLER_ADM.ADD_STMT_TO_HANDLER( handler_name IN VARCHAR2, statement IN CLOB, execution_sequence IN NUMBER DEFAULT NULL);
Parameters
Table 144-5 ADD_STMT_TO_HANDLER Procedure Parameters
Parameter | Description |
---|---|
|
The name of the statement DML handler. |
|
The text of the SQL statement to add to the statement DML handler. If |
|
The position of the statement in the statement DML handler at which a SQL statement is to be set to execute. Statements are executed in order from the lowest execution sequence number to the highest execution sequence number. You can specify a positive or negative integer or decimal, or you can specify 0 (zero). If you specify an execution sequence number that is used by an existing statement in the statement DML handler, then the statement in the If |
This procedure creates a statement DML handler.
Syntax
DBMS_STREAMS_HANDLER_ADM.CREATE_STMT_HANDLER( handler_name IN VARCHAR2, comment IN VARCHAR2 DEFAULT NULL);
Parameters
Table 144-6 CREATE_STMT_HANDLER Procedure Parameters
Parameter | Description |
---|---|
|
The name of the statement DML handler. |
|
A comment for the statement DML handler. If |
This procedure drops a statement DML handler.
Syntax
DBMS_STREAMS_HANDLER_ADM.DROP_STMT_HANDLER( handler_name IN VARCHAR2);
Parameters
Table 144-7 DROP_STMT_HANDLER Procedure Parameters
Parameter | Description |
---|---|
|
The name of the statement DML handler. |
This procedure removes a statement from a statement DML handler.
Syntax
DBMS_STREAMS_HANDLER_ADM.REMOVE_STMT_FROM_HANDLER( handler_name IN VARCHAR2, execution_sequence IN NUMBER DEFAULT NULL);
Parameters
Table 144-8 REMOVE_STMT_FROM_HANDLER Procedure Parameters
Parameter | Description |
---|---|
|
The name of the statement DML handler. |
|
The position of the statement to remove. You can specify a positive or negative integer or decimal, or you can specify 0 (zero). If If the specified execution sequence number does not exist for the statement DML handler, then the procedure raises an error. |