You are on page 1of 5

Rules Used in Oracle Streams:

Rule:
A rule is a database object that enables a client to perform an action when an event
occurs and a condition is satisfied. Rules are evaluated by a rules engine, which is a
built-in part of Oracle. Both user-created applications and Oracle features, such as
Streams, can be clients of the rules engine.

Rule Condition:
A rule condition combines one or more expressions and conditions and returns a
Boolean value.

Rule Set Evaluation Process


1. A client-defined event occurs.
2. The client initiates evaluation of a rule set by sending information about an
event to the rules engine using the DBMS_RULE.EVALUATE procedure.
3. The rules engine evaluates the rule set for the event using the relevant
evaluation context.
4. The rules engine obtains the results of the evaluation. Each rule evaluates to
either TRUE, FALSE, or NULL (unknown).
5. The client performs actions based on the results returned by the rules engine.

In Oracle Streams, each of the following mechanisms is called a Oracle Streams client because each
one is a client of a rules engine, when the mechanism is associated with one or more rule sets

 Capture process

 Propagation

 Apply process

Each of these clients can be associated with at most two rule sets:
a positive rule set and a negative rule set.
An Oracle Streams client performs a task if a message satisfies its rule sets.
Specifically, you use rule sets in Oracle Streams to do the following:
Specify the changes that a capture process captures from the redo log or discards. That is, if a change
found in the redo log satisfies the rule sets for a capture process, then the capture process captures
the change. If a change found in the redo log causes does not satisfy the rule sets for a capture
process, then the capture process discards the change.
The above procedure is common for remaining two components of the process.

Packages :
DBMS_STREAMS_ADM Package:
The DBMS_STREAMS_ADM package provides an administrative interface for adding
and removing simple rules for capture processes, propagations, and apply
processes at the table, schema, and database level.
DBMS_CAPTURE_ADM Package:
The DBMS_CAPTURE_ADM package provides an administrative interface for starting,
stopping, and configuring a capture process.
Datatypes Captured

a capture process can capture changes made to columns of the following datatypes:
VARCHAR2
NVARCHAR2
NUMBER
LONG
DATE
BINARY_FLOAT
BINARY_DOUBLE
TIMESTAMP
TIMESTAMP WITH TIME ZONE
TIMESTAMP WITH LOCAL TIME ZONE
INTERVAL YEAR TO MONTH
INTERVAL DAY TO SECOND
RAW
LONG RAW
CHAR
NCHAR
CLOB
NCLOB
BLOB
A capture process does not capture the results of DML changes to columns of the
following datatypes: BFILE, ROWID, and user-defined types (including object types,
REFs, varrays, nested tables, and Oracle-supplied types). A capture process raises
an error if it tries to create a row LCR for a DML change to a table containing a
column of an unsupported datatype.
DBMS_APPLY_ADM Package :
The DBMS_CAPTURE_ADM package provides an administrative interface for starting,
stopping, and configuring a capture process.
DBMS_RULE Package
The DBMS_RULE package contains the EVALUATE procedure, which evaluates a rule
set. The goal of this procedure is to produce the list of satisfied rules, based on the
data.

Global Rules Example:

Run the ADD_GLOBAL_RULES procedure to create the rules:

BEGIN
DBMS_STREAMS_ADM.ADD_GLOBAL_RULES(
streams_type => 'capture',
streams_name => 'capture',
queue_name => 'streams_queue',
include_dml => TRUE,
include_ddl => TRUE,
include_tagged_lcr => FALSE,
source_database => NULL,
inclusion_rule => TRUE);
END;
/

This is a rule to capture DML and DDL operations at entire


database level.
Schema Rule Example:
BEGIN
DBMS_STREAMS_ADM.ADD_SCHEMA_PROPAGATION_RULES(
schema_name => 'hr',
streams_name => 'dbs1_to_dbs2',
source_queue_name => 'streams_queue',
destination_queue_name => 'streams_queue@dbs2.net',
include_dml => TRUE,
include_ddl => TRUE,
include_tagged_lcr => FALSE,
source_database => 'dbs1.net',
inclusion_rule => TRUE);
END;
/
Table Rules:
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_RULES(
table_name => 'hr.locations',
streams_type => 'apply',
streams_name => 'apply',
queue_name => 'streams_queue',
include_dml => TRUE,
include_ddl => FALSE,
include_tagged_lcr => FALSE,
source_database => 'dbs1.net',
inclusion_rule => TRUE);
END;
/

Subset Rules
A subset rule is a special type of table rule for DML
changes that is relevant only to a subset of the rows in a
table.

Row Migration and Subset Rules

When you use subset rules, an update operation can be converted into an insert or
delete operation when it is captured, propagated, applied, or dequeued. This
automatic conversion is called row migration .

Subset Rules Example

This example instructs an Oracle Streams apply process to apply a subset of row
LCRs relating to the hr.regions table where the region_id is 2. These
changes originated at the dbs1.net source database.

Run the ADD_SUBSET_RULES procedure to create three rules:

BEGIN
DBMS_STREAMS_ADM.ADD_SUBSET_RULES(
table_name => 'hr.regions',
dml_condition => 'region_id=2',
streams_type => 'apply',
streams_name => 'apply',
queue_name => 'streams_queue',
include_tagged_lcr => FALSE,
source_database => 'dbs1.net');
END;
/

For example, suppose you use a subset rule to specify that a capture process or a
synchronous capture captures changes to the hr.employees table where the
employee's department_id is 50 using the following subset condition:
department_id = 50. Assume that the table at the source database contains records
for employees from all departments. If a DML operation changes an employee's
department_id from 80 to 50, then the subset rule converts the update operation
into an insert operation and captures the change.

You might also like