In Oracle Streams, a rule-based transformation is any modification to a message that results when a rule in a positive rule set evaluates to TRUE
. There are two types of rule-based transformations: declarative and custom.
The following sections describe managing rule-based transformations:
Note:
A transformation specified for a rule is performed only if the rule is in a positive rule set. If the rule is in the negative rule set for a capture process, propagation, apply process, or messaging client, then these Oracle Streams clients ignore the rule-based transformation.
See Also:
You can use the following procedures in the DBMS_STREAMS_ADM
package to manage declarative rule-based transformations: ADD_COLUMN
, DELETE_COLUMN
, KEEP_COLUMNS
, RENAME_COLUMN
, RENAME_SCHEMA
, and RENAME_TABLE
.
This section provides instructions for completing the following tasks:
The following topics contain examples that add declarative rule-based transformations to DML rules:
Adding a Declarative Rule-Based Transformation that Adds a Column
Adding a Declarative Rule-Based Transformation that Renames a Table
Note:
Declarative rule-based transformations can be specified for DML rules only. They cannot be specified for DDL rules.
Use the RENAME_TABLE
procedure in the DBMS_STREAMS_ADM
package to add a declarative rule-based transformation that renames a table in a row LCR. For example, the following procedure adds a declarative rule-based transformation to the jobs12
rule in the strmadmin
schema:
BEGIN DBMS_STREAMS_ADM.RENAME_TABLE( rule_name => 'strmadmin.jobs12', from_table_name => 'hr.jobs', to_table_name => 'hr.assignments', step_number => 0, operation => 'ADD'); END; /
The declarative rule-based transformation added by this procedure renames the table hr.jobs
to hr.assignments
in a row LCR when the rule jobs12
evaluates to TRUE
for the row LCR. If more than one declarative rule-based transformation is specified for the jobs12
rule, then this transformation follows default transformation ordering because the step_number
parameter is set to 0
(zero). In addition, the operation
parameter is set to ADD
to indicate that the transformation is being added to the rule, not removed from it.
The RENAME_TABLE
procedure can also add a transformation that renames the schema in addition to the table. For example, in the previous example, to specify that the schema should be renamed to oe
, specify oe.assignments
for the to_table_name
parameter.
Use the ADD_COLUMN
procedure in the DBMS_STREAMS_ADM
package to add a declarative rule-based transformation that adds a column to a row in a row LCR. For example, the following procedure adds a declarative rule-based transformation to the employees35
rule in the strmadmin
schema:
BEGIN DBMS_STREAMS_ADM.ADD_COLUMN( rule_name => 'employees35', table_name => 'hr.employees', column_name => 'birth_date', column_value => ANYDATA.ConvertDate(NULL), value_type => 'NEW', step_number => 0, operation => 'ADD'); END; /
The declarative rule-based transformation added by this procedure adds a birth_date
column of data type DATE
to an hr.employees
table row in a row LCR when the rule employees35
evaluates to TRUE
for the row LCR.
Notice that the ANYDATA.ConvertDate
function specifies the column type and the column value. In this example, the added column value is NULL
, but a valid date can also be specified. Use the appropriate ANYDATA
function for the column being added. For example, if the data type of the column being added is NUMBER
, then use the ANYDATA.ConvertNumber
function.
The value_type
parameter is set to NEW
to indicate that the column is added to the new values in a row LCR. You can also specify OLD
to add the column to the old values.
If more than one declarative rule-based transformation is specified for the employees35
rule, then the transformation follows default transformation ordering because the step_number
parameter is set to 0
(zero). In addition, the operation
parameter is set to ADD
to indicate that the transformation is being added, not removed.
Note:
The ADD_COLUMN
procedure is overloaded. A column_function
parameter can specify that the current system date or time stamp is the value for the added column. The column_value
and column_function
parameters are mutually exclusive.
See Also:
Oracle Database PL/SQL Packages and Types Reference for more information about AnyData
type functions
When the operation
parameter is set to ADD
in a procedure that adds a declarative rule-based transformation, an existing declarative rule-based transformation is overwritten if the parameters in the following list match the existing transformation parameters:
ADD_COLUMN
procedure: rule_name
, table_name
, column_name
, and step_number
parameters
DELETE_COLUMN
procedure: rule_name
, table_name
, column_name
, and step_number
parameters
KEEP_COLUMNS
procedure: rule_name
, table_name
, column_list
, and step_number
parameters, or rule_name
, table_name
, column_table
, and step_number
parameters (The column_list
and column_table
parameters are mutually exclusive.)
RENAME_COLUMN
procedure: rule_name
, table_name
, from_column_name
, and step_number
parameters
RENAME_SCHEMA
procedure: rule_name
, from_schema_name
, and step_number
parameters
RENAME_TABLE
procedure: rule_name
, from_table_name
, and step_number
parameters
For example, suppose an existing declarative rule-based transformation was creating by running the following procedure:
BEGIN DBMS_STREAMS_ADM.RENAME_COLUMN( rule_name => 'departments33', table_name => 'hr.departments', from_column_name => 'manager_id', to_column_name => 'lead_id', value_type => 'NEW', step_number => 0, operation => 'ADD'); END; /
Running the following procedure overwrites this existing declarative rule-based transformation:
BEGIN DBMS_STREAMS_ADM.RENAME_COLUMN( rule_name => 'departments33', table_name => 'hr.departments', from_column_name => 'manager_id', to_column_name => 'lead_id', value_type => '*', step_number => 0, operation => 'ADD'); END; /
In this case, the value_type
parameter in the declarative rule-based transformation was changed from NEW
to *
. That is, in the original transformation, only new values were renamed in row LCRs, but, in the new transformation, both old and new values are renamed in row LCRs.
To remove a declarative rule-based transformation from a rule, use the same procedure used to add the transformation, but specify REMOVE
for the operation
parameter. For example, to remove the transformation added in "Adding a Declarative Rule-Based Transformation that Renames a Table", run the following procedure:
BEGIN DBMS_STREAMS_ADM.RENAME_TABLE( rule_name => 'strmadmin.jobs12', from_table_name => 'hr.jobs', to_table_name => 'hr.assignments', step_number => 0, operation => 'REMOVE'); END; /
When the operation
parameter is set to REMOVE
in any of the declarative transformation procedures listed in "Managing Declarative Rule-Based Transformations", the other parameters in the procedure are optional, excluding the rule_name
parameter. If these optional parameters are set to NULL
, then they become wildcards.
The RENAME_TABLE
procedure in the previous example behaves in the following way when one or more of the optional parameters are set to NULL
:
from_table_name Parameter | to_table_name Parameter | step_number Parameter | Result |
---|---|---|---|
|
|
|
Remove all rename table transformations for the specified rule |
non- |
|
|
Remove all rename table transformations with the specified |
|
non- |
|
Remove all rename table transformations with the specified |
|
|
non- |
Remove all rename table transformations with the specified |
non- |
non- |
|
Remove all rename table transformations with the specified |
|
non- |
non- |
Remove all rename table transformations with the specified |
non- |
|
non- |
Remove all rename table transformations with the specified |
The other declarative transformation procedures work in a similar way when optional parameters are set to NULL
and the operation parameter is set to REMOVE
.
Use the SET_RULE_TRANSFORM_FUNCTION
procedure in the DBMS_STREAMS_ADM
package to set or unset a custom rule-based transformation for a rule. This procedure modifies the rule action context to specify the custom rule-based transformation.
This section provides instructions for completing the following tasks:
Note:
Do not modify LONG
, LONG
RAW
, LOB, or XMLType
column data in an LCR with a custom rule-based transformation.
Note:
There is no automatic locking mechanism for a rule action context. Therefore, ensure that an action context is not updated by two or more sessions at the same time.
When you perform custom rule-based transformations on DDL LCRs, you probably need to modify the DDL text in the DDL LCR to match any other modification. For example, if the transformation changes the name of a table in the DDL LCR, then the transformation should change the table name in the DDL text in the same way.
A custom rule-based transformation function always operates on one message, but it can return one message or many messages. A custom rule-based transformation function that returns one message is a one-to-one transformation function. A one-to-one transformation function must have the following signature:
FUNCTION user_function ( parameter_name IN ANYDATA) RETURN ANYDATA;
Here, user_function
stands for the name of the function and parameter_name
stands for the name of the parameter passed to the function. The parameter passed to the function is an ANYDATA
encapsulation of a message, and the function must return an ANYDATA
encapsulation of a message.
A custom rule-based transformation function that can return more than one message is a one-to-many transformation function. A one-to-many transformation function must have the following signature:
FUNCTION user_function ( parameter_name IN ANYDATA) RETURN STREAMS$_ANYDATA_ARRAY;
Here, user_function
stands for the name of the function and parameter_name
stands for the name of the parameter passed to the function. The parameter passed to the function is an ANYDATA
encapsulation of a message, and the function must return an array that contains zero or more ANYDATA
encapsulations of a message. If the array contains zero ANYDATA
encapsulations of a message, then the original message is discarded. One-to-many transformation functions are supported only for Oracle Streams capture processes and synchronous captures.
The STREAMS$_ANYDATA_ARRAY
type is an Oracle-supplied type that has the following definition:
CREATE OR REPLACE TYPE SYS.STREAMS$_ANYDATA_ARRAY AS VARRAY(2147483647) of SYS.ANYDATA /
The following steps outline the general procedure for creating a custom rule-based transformation that uses a one-to-one function:
Now, if you run the query that displays the name-value pairs in the action context for these rules, each rule, including the DEPARTMENTS6
rule, shows the name-value pair for the custom rule-based transformation:
SELECT RULE_NAME, AC.NVN_NAME ACTION_CONTEXT_NAME, AC.NVN_VALUE.ACCESSVARCHAR2() ACTION_CONTEXT_VALUE FROM DBA_RULES R, TABLE(R.RULE_ACTION_CONTEXT.ACTX_LIST) AC WHERE RULE_NAME IN ('DEPARTMENTS5','DEPARTMENTS6','DEPARTMENTS7');
This query displays output similar to the following:
Rule Name Action Context Name Action Context Value ------------- --------------------------- ------------------------------ DEPARTMENTS5 STREAMS$_ROW_SUBSET INSERT DEPARTMENTS5 STREAMS$_TRANSFORM_FUNCTION "HR"."EXECUTIVE_TO_MANAGEMENT" DEPARTMENTS6 STREAMS$_TRANSFORM_FUNCTION "HR"."EXECUTIVE_TO_MANAGEMENT" DEPARTMENTS7 STREAMS$_ROW_SUBSET DELETE DEPARTMENTS7 STREAMS$_TRANSFORM_FUNCTION "HR"."EXECUTIVE_TO_MANAGEMENT"
You can also view transformation functions using the DBA_STREAMS_TRANSFORM_FUNCTION
data dictionary view.
See Also:
Oracle Database PL/SQL Packages and Types Reference for more information about the SET_RULE_TRANSFORM_FUNCTION
and the rule types used in this example
To alter a custom rule-based transformation, you can either edit the transformation function or run the SET_RULE_TRANSFORM_FUNCTION
procedure to specify a different transformation function. This example runs the SET_RULE_TRANSFORM_FUNCTION
procedure to specify a different transformation function. The SET_RULE_TRANSFORM_FUNCTION
procedure modifies the action context of a specified rule to run a different transformation function. If you edit the transformation function itself, then you do not need to run this procedure.
This example alters a custom rule-based transformation for rule DEPARTMENTS5
by changing the transformation function from hr.execute_to_management
to hr.executive_to_lead
. The hr.execute_to_management
rule-based transformation was added to the DEPARTMENTS5
rule in the example in "Creating a Custom Rule-Based Transformation".
In Oracle Streams, subset rules use name-value pairs in an action context to perform internal transformations that convert UPDATE
operations into INSERT
and DELETE
operations in some situations. Such a conversion is called a row migration. The SET_RULE_TRANSFORM_FUNCTION
procedure preserves the name-value pairs that perform row migrations.
See Also:
"Row Migration and Subset Rules" for more information about row migration
Complete the following steps to alter a custom rule-based transformation:
Note:
The SET_RULE_TRANSFORM_FUNCTION
does not verify that the specified transformation function exists. If the function does not exist, then an error is raised when an Oracle Streams process or job tries to invoke the transformation function.
If a custom rule-based transformation function is modified at the same time that an Oracle Streams client tries to access it, then an error might be raised.
To unset a custom rule-based transformation from a rule, run the SET_RULE_TRANSFORM_FUNCTION
procedure and specify NULL
for the transformation function. Specifying NULL
unsets the name-value pair that specifies the custom rule-based transformation in the rule action context. This example unsets a custom rule-based transformation for rule DEPARTMENTS5
. This transformation was added to the DEPARTMENTS5
rule in the example in "Creating a Custom Rule-Based Transformation".
In Oracle Streams, subset rules use name-value pairs in an action context to perform internal transformations that convert UPDATE
operations into INSERT
and DELETE
operations in some situations. Such a conversion is called a row migration. The SET_RULE_TRANSFORM_FUNCTION
procedure preserves the name-value pairs that perform row migrations.
See Also:
"Row Migration and Subset Rules" for more information about row migration
Run the following procedure to unset the custom rule-based transformation for rule DEPARTMENTS5
:
BEGIN DBMS_STREAMS_ADM.SET_RULE_TRANSFORM_FUNCTION( rule_name => 'departments5', transform_function => NULL); END; /
To ensure that the transformation function was unset, you can run the query in Step 1. You should alter the action context for the DEPARTMENTS6
and DEPARTMENTS7
rules in a similar way to keep the three subset rules consistent.
See Also:
"Row Migration and Subset Rules" for more information about row migration