Skip Headers
Oracle® Database PL/SQL Packages and Types Reference
10g Release 2 (10.2)

Part Number B14258-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

88 DBMS_RLMGR

The DBMS_RLMGR package contains various procedures to create and manage rules and rule sessions by the Rules Manager.

See Also:

Oracle Database Application Developer's Guide - Rules Manager and Expression Filter for more information.

This chapter contains the following topic:


Summary of Rules Manager Subprograms

Table 88-1 describes the subprograms in the DBMS_RLMGR package.

All the values and names passed to the procedures defined in the DBMS_RLMGR package are case insensitive unless otherwise mentioned. In order to preserve the case, double quotation marks should be used around the values.

Table 88-1 DBMS_RLMGR Package Subprograms

Subprogram Description

ADD_ELEMENTARY_ATTRIBUTE Procedures

Adds the specified attribute to the event structure (also the Expression Filter attribute set)

ADD_EVENT Procedures

Adds an event to a rule class in an active session

ADD_FUNCTIONS Procedure

Adds a Function, a Type, or a Package to the approved list of functions with an event structure (also the Expression Filter attribute set)

ADD_RULE Procedure

Adds a rule to the rule class

CONSUME_EVENT Function

Consumes an event using its identifiers and prepares the corresponding rule for action execution

CONSUME_PRIM_EVENTS Function

Consumes one or more primitive events with all or none semantics

CREATE_EVENT_STRUCTURE Procedure

Creates an event structure

CREATE_RULE_CLASS Procedure

Creates a rule class

DELETE_RULE Procedure

Deletes a rule from a rule class

DROP_EVENT_STRUCTURE Procedure

Drops an event structure

DROP_RULE_CLASS Procedure

Drops a rule class

GRANT_PRIVILEGE Procedure

Grants a privilege on a rule class to another user

PROCESS_RULES Procedure

Process the rules for a given event

RESET_SESSION Procedure

Starts a new rule session within a database session

REVOKE_PRIVILEGE Procedure

Revokes a privilege on a rule class from a user



ADD_ELEMENTARY_ATTRIBUTE Procedures

This procedure adds the specified attribute to an event structure, which is also the Expression Filter attribute set. The procedure is overloaded. The different functionality of each form of syntax is presented along with the definitions.

Syntax

Adds the specified elementary attribute to the attribute set:

DBMS_RLMGR.ADD_ELEMENTARY_ATTRIBUTE (
              event_struct   IN   VARCHAR2,
              attr_name      IN   VARCHAR2,
              attr_type      IN   VARCHAR2,
              attr_defvl     IN   VARCHAR2 default NULL);
 

Identifies the elementary attributes that are table aliases and adds them to the event structure:

DBMS_RLMGR.ADD_ELEMENTARY_ATTRIBUTE (
              event_struct   IN   VARCHAR2,
              attr_name      IN   VARCHAR2,
              tab_alias      IN   rlm$table_alias);

Parameters

Table 88-2 ADD_ELEMENTARY_ATTRIBUTE Procedure Parameters

Parameter Description

event_struct

Name of the event structure or attribute set to which this attribute is added

attr_name

Name of the elementary attribute to be added. No two attributes in a set can have the same name.

attr_type

Datatype of the attribute. This argument accepts any standard SQL datatype or the name of an object type that is accessible to the current user.

tab_alias

The type that identifies the database table to which the attribute is aliased

attr_defv1

Default value for the elementary attribute


Usage Notes

Examples

The following commands add two elementary attributes to an attribute set:

BEGIN
  DBMS_RLMGR.ADD_ELEMENTARY_ATTRIBUTE (
                               event_struct  => 'HRAttrSet',
                               attr_name => 'HRREP',
                               attr_type => 'VARCHAR2(30)');
  DBMS_RLMGR.ADD_ELEMENTARY_ATTRIBUTE (
                               event_struct  => 'HRAttrSet',
                               attr_name => 'DEPT',
                               tab_alias => exf$table_alias('DEPT'));
END;

ADD_EVENT Procedures

This procedure adds a primitive event to a rule class in an active rule session. The procedure is overloaded. The different functionality of each form of syntax is presented along with the definitions.

Syntax

Adds a string representation of the primitive event instance to a rule class:

DBMS_RLMGR.ADD_EVENT (
   rule_class      IN VARCHAR2,
   event_inst      IN VARCHAR2,
   event_type      IN VARCHAR2 default null);

Adds an AnyData representation of the primitive event instance to a rule class:

DBMS_RLMGR.ADD_EVENT (
   rule_class      IN VARCHAR2,
   event_inst      IN sys.AnyData);

Parameters

Table 88-3 ADD_EVENT Procedure Parameters

Parameter Description

rule_class

Name of the rule class. A schema extended rule class name can be used to refer to a rule class that does not belong to the current schema.

event_inst

String or AnyData representation of the event instance being added to the rule class

event_type

Type of event instance assigned to the event_inst argument when the string representation of the event instance is used for a rule class configured for composite events


Usage Notes

Examples

The following commands add two events to the CompTravelPromo rule class that is configured for two types of primitive events (AddFlight and AddRentalCar).

BEGIN
 DBMS_RLMGR.ADD_EVENT(rule_class => 'CompTravelPromo',
                     event_inst =>
                        AddFlight.getVarchar(987, 'Abcair', 'Boston',
                                         'Orlando', '01-APR-2003', '08-APR-2003'),
                     event_type => 'AddFlight');

DBMS_RLMGR.ADD_EVENT(rule_class => 'Scott.CompTravelPromo',
                     event_inst =>
                        AnyData.convertObject(
                                        AddRentalCar(987, 'Luxury', '03-APR-2003',
                                                     '08-APR-2003', NULL)));
END;

ADD_FUNCTIONS Procedure

This procedure adds a user-defined function, package, or type representing a set of functions to the event structure, which is also the Expression Filter attribute set.

Syntax

DBMS_RLMGR.ADD_FUNCTIONS (
   event_struct   IN   VARCHAR2,
   funcs_name     IN   VARCHAR2);

Parameters

Table 88-4 ADD_FUNCTIONS Procedure Parameters

Parameter Description

event_struct

Name of the event structure to which the functions are added

funcs_name

Name of a function, package, or type (representing a function set) or its synonyms


Usage Notes

Examples

The following commands add two functions to the attribute set:

BEGIN 
  DBMS_RLMGR.ADD_FUNCTIONS (attr_set   => 'Car4Sale', 
                             funcs_name => 'HorsePower');
  DBMS_RLMGR.ADD_FUNCTIONS (attr_set   => 'Car4Sale', 
                             funcs_name => 'Scott.CrashTestRating');
END;

ADD_RULE Procedure

This procedure adds new rules to a rule class.

Syntax

DBMS_RLMGR.ADD_RULE (
   rule_class      IN  VARCHAR2,
   rule_id         IN  VARCHAR2,
   rule_cond       IN  VARCHAR2,
   actprf_nml      IN  VARCHAR2 DEFAULT NULL,
   actprf_vall     IN  VARCHAR2 DEFAULT NULL);

Parameters

Table 88-5 ADD_RULE Procedure Parameters

Parameter Description

rule_class

Name of the rule class. A schema extended rule class name can be used to refer to a rule class that does not belong to the current schema.

rule_id

Unique identifier for the rule within the rule class

rule_cond

The condition for the rule. The condition uses the variables defined in the rule class's event structure.

actprf_nml

The list of action preference names for which values will be assigned through the actprf_vall argument

actprf_vall

The list of action preference values for the names list assigned to the actprf_nml argument


Usage Notes

Examples

The following command adds a rule to the rule class.

BEGIN
DBMS_RLMGR.ADD_RULE (
           rule_class => 'CompTravelPromo',
           rule_id => 'AB_AV_FL',
           rule_cond =>
             '<condition>
                 <and join="Flt.CustId = Car.CustId">
                    <object name="Flt">
                      Airline=''Abcair'' and ToCity=''Orlando''
                    </object>
                    <object name="Car">
                      CarType = ''Luxury''
                    </object>
                  </and>
               </condition>' ,
             actprf_nml => 'PromoType, OfferedBy',
             actprf_vall => '''RentalCar'', ''Acar''');
END;

With proper privileges, the following SQL INSERT statement can be used to add the rule to the rule class.

INSERT INTO CompTravelPromo (rlm$ruleid, rlm$rulecond, PromoType, OfferedBy)
  VALUES ('AB_AV_FL',
          '<condition>
             <and join="Flt.CustId = Car.CustId">
               <object name="Flt">
                   Airline=''Abcair'' and ToCity=''Orlando''
               </object>
               <object name="Car">
                   CarType = ''Luxury''
               </object>
             </and>
           </condition>',
          'RentalCar','Acar');

CONSUME_EVENT Function

This function consumes an event and prepares the corresponding rule for action execution. This is required only when the action (or rule execution) is carried by the user's application and not in the callback.

Syntax

DBMS_RLMGR.CONSUME_EVENT (
   rule_class       IN VARCHAR2,
   event_ident      IN VARCHAR2) 
 RETURN NUMBER;

Parameters

Table 88-6 CONSUME_EVENT Function Parameters

Parameter Description

rule_class

Name of the rule class. A schema extended rule class name can be used to refer to a rule class that does not belong to the current schema.

event_ident

Event identifier obtained from the corresponding rule class results view (or arguments of the action callback procedure in the case of rule class configured for RULE based consumption policy)


Returns

The function returns:

Usage Notes

Examples

The following commands identify an event that is used for a rule execution and consumes it using its identifier.

var eventid VARCHAR(40);
var evtcnsmd NUMBER;

BEGIN
  SELECT rlm$eventid INTO :eventid FROM MatchingPromos WHERE rownum < 2;

  -- carry the required action for a rule matched by the above event --
  :evtcnsmd := DBMS_RLMGR.CONSUME_EVENT(rule_class  => 'TravelPromotion',
                                        event_ident => :eventid);
END;

CONSUME_PRIM_EVENTS Function

This function consumes a set of primitive events with all or nothing semantics in the case of a rule class configured with RULE based consumption policy.

Syntax

DBMS_RLMGR.CONSUME_PRIM_EVENTS (
   rule_class       IN VARCHAR2,
   event_idents     IN RLM$EVENTIDS) 
 RETURN NUMBER;

Parameters

Table 88-7 CONSUME_PRIM_EVENTS Function Parameters

Parameter Description

rule_class

Name of the rule class. A schema extended rule class name can be used to refer to a rule class that does not belong to the current schema.

event_ident

Event identifiers obtained from the corresponding rule class results view or the arguments of the action callback procedure


Returns

The function returns:

Usage Notes

When the rule class is configured for RULE based consumption policy, the CONSUME_PRIM_EVENTS function can be used to consume one or more primitive events that constitute a composite event. This operation will succeed only when all the events passed in are still valid and are available for consumption. Any user initiated action should be implemented after checking the return value of the CONSUME_PRIM_EVENTS call.

Examples

The following commands show the body of the action callback procedure for a rule class configured for RULE consumption policy. This demonstrates the use of CONSUME_PRIM_EVENTS procedure to consume the events before executing the action for the matched rules.

create or replace procedure PromoAction (
      Flt        AddFlight, 
      Flt_EvtId  ROWID,    --- rowid for the flight primitive event
      Car        AddRentalCar, 
      Car_EvtId  ROWID, 
      rlm$rule   TravelPromotions%ROWTYPE) is 
  evtcnsmd   NUMBER; 
BEGIN
  evtcnsmd := DBMS_RLMGR.CONSUME_PRIM_EVENTS(
                    rule_class   => 'TravelPromotions',
                    event_idents => RLM$EVENTIDS(Flt_EvtId, Car_EvtId));

  if (evtcnsmd = 1) then 
    -- consume operation was successful; perform the action ---
    OfferPromotion (Flt.CustId, rlm$rule.PromoType, rlm$rule.OfferedBy);
  end if;
END;

CREATE_EVENT_STRUCTURE Procedure

This procedure creates an event structure.

Syntax

DBMS_RLMGR.CREATE_EVENT_STRUCTURE  (
   event_struct  IN  VARCHAR2);

Parameters

Table 88-8 CREATE_EVENT_ STRUCTURE Procedure Parameter

Parameter Description

event_struct

Name of the event structure to be created in the current schema


Usage Notes

This procedure creates a dummy the event structure in the current schema. One or more attributes can be added to this event structure using the ADD_ELEMENTARY_ATTRIBUTE procedure.

Examples

The following command creates the event structure.

BEGIN
  DBMS_RLMGR.CREATE_EVENT_STRUCT(event_struct => 'AddFlight');
END;

CREATE_RULE_CLASS Procedure

This procedure creates a rule class.

Syntax

DBMS_RLMGR.CREATE_RULE_CLASS  (
   rule_class      IN  VARCHAR2,
   event_struct    IN  VARCHAR2,
   action_cbk      IN  VARCHAR2,
   actprf_spec     IN  VARCHAR2  default null,
   rslt_viewnm     IN  VARCHAR2  default null,
   rlcls_prop      IN  VARCHAR2  default <simple/>);

Parameters

Table 88-9 CREATE_RULE_CLASS Procedure Parameters

Parameter Description

rule_class

The name of the rule class to be created in the current schema

event_struct

The name of the object type or an Expression Filter attribute set in the current schema that represents the event structure for the rule class

action_cbk

The name of the action callback procedure to be created for the rule class

actprf_spec

The specification (name and SQL datatype pairs) for the action preferences associated with the rule class

rlst_viewnm

The name of the rule class results view that lists the matching events and rules within a session. A view with this name is created in the current schema.

rlcls_prop

The XML document for setting the rule class properties. By default, the rule class created is for simple events (non-composite).


Usage Notes

Examples

The following commands create a rule class for simple events (of AddFlight type).

CREATE or REPLACE TYPE AddFlight AS OBJECT (
                  CustId NUMBER,
                  Airline VARCHAR(20),
                  FromCity VARCHAR(30),
                  ToCity VARCHAR(30),
                  Depart DATE,
                  Return DATE);
BEGIN
  DBMS_RLMGR.CREATE_RULE_CLASS (
              rule_class   => 'TravelPromotion', -- rule class name --
              event_struct => 'AddFlight', -- event struct name --
              action_cbk    => 'PromoAction', -- callback proc name –-
              rslt_viewnm   => 'MatchingPromos', -- results view --
              actprf_spec   => 'PromoType VARCHAR(20),
                              OfferedBy VARCHAR(20)');
END;

The following commands create a rule class for composite events consisting of two primitive events (AddFlight and AddRentalCar).

CREATE or REPLACE TYPE TSCompEvent (Flt AddFlight,
                                    Car AddRentalCar);
BEGIN
  DBMS_RLMGR.CREATE_RULE_CLASS (
              rule_class    => 'CompTravelPromo', -- rule class name --
              event_struct  => 'TSCompEvent', -- event struct name --
              action_cbk    => 'CompPromoAction', -- callback proc name –-
              rslt_viewnm   => 'MatchingCompPromos', -- results view --
              actprf_spec   => 'PromoType VARCHAR(20),
                              OfferedBy VARCHAR(20)',
              properties    => '<composite/>');
END;

DELETE_RULE Procedure

This procedure deletes a rule from a rule class.

Syntax

DBMS_RLMGR.DELETE_RULE (
   rule_class    IN    VARCHAR2,
   rule_id       IN    VARCHAR2);

Parameters

Table 88-10 DELETE_RULE Procedure Parameters

Parameter Description

rule_class

Name of the rule class. A schema extended rule class name can be used to refer to a rule class that does not belong to the current schema.

rule_id

Identifier for the rule to be deleted


Usage Notes

Examples

The following command deletes a rule from the rule class.

BEGIN
  DBMS_RLMGR.DELETE_RULE (
           rule_class  => 'CompTravelPromo',
           rule_id     => 'AB_AV_FL');
END;

Alternately, the following SQL DELETE statement can be issued to delete the above rule from the rule class.

DELETE FROM CompTravelPromo WHERE rlm$ruleid = 'AB_AV_FL';

DROP_EVENT_STRUCTURE Procedure

This procedure drops an event structure.

Syntax

DBMS_RLMGR.DROP_EVENT_STRUCTURE  (
   event_struct  IN  VARCHAR2);

Parameters

Table 88-11 DROP_EVENT_ STRUCTURE Procedure Parameter

Parameter Description

event_struct

Name of the event structure in the current schema


Usage Notes

This procedure drops the event structure from the current schema. This drops all the dependent objects created to manage the event structure.

Examples

The following command drops the event structure.

BEGIN
  DBMS_RLMGR.DROP_EVENT_STRUCT(event_struct => 'AddFlight');
END;

DROP_RULE_CLASS Procedure

This procedure drops a rule class.

Syntax

DBMS_RLMGR.DROP_RULE_CLASS  (
   rule_class  IN  VARCHAR2);

Parameters

Table 88-12 DROP_RULE_CLASS Procedure Parameter

Parameter Description

rule_class

The name of the rule class in the current schema


Usage Notes

This procedure drops the rule class from the current schema. This drops all the dependent objects created to manage the rule class. Because an event structure in a user's schema can be shared across multiple rule classes, the event structure is not dropped with this command. The DROP_EVENT_STRUCTURE API should be used for the composite event as well as the individual primitive events to cleanup unused event structures.

Examples

The following command drops the rule class.

BEGIN
  DBMS_RLMGR.DROP_RULE_CLASS(rule_class => 'CompTravelPromo');
END;

GRANT_PRIVILEGE Procedure

This procedure grants privileges on a rule class to another user.

Syntax

DBMS_RLMGR.GRANT_PRIVILEGE  (
   rule_class      IN  VARCHAR2,
   priv_type       IN  VARCHAR2,
   to_user         IN  VARCHAR2);

Parameters

Table 88-13 GRANT_PRIVILEGE Procedure Parameters

Parameter Description

rule_class

The name of the rule class in the current schema

priv_type

Type of rule class privilege to be granted

to_user

The user to whom the privilege is to be granted


Usage Notes

Examples

The following command grants PROCESS RULES privilege on TravelPromo rule class to the user SCOTT.

BEGIN
  DBMS_RLMGR.GRANT_PRIVILEGE(rule_class => 'TravelPromo',
                             priv_type => 'PROCESS RULES',
                             to_user => 'SCOTT');
END;

PROCESS_RULES Procedure

This procedure processes the rules for a given event. The procedure is overloaded. The different functionality of each form of syntax is presented along with the definitions.

Syntax

Processes the rules for a string representation of the event instance being added to the rule class:

DBMS_RLMGR.PROCESS_RULES  (
   rule_class    IN  VARCHAR2,
   event_inst    IN  VARCHAR2,
   event_type    IN  VARCHAR2 default null);

Processes the rules for an AnyData representation of the event instance being added to the rule class:

DBMS_RLMGR.PROCESS_RULES  (
   rule_class    IN  VARCHAR2,
   event_inst    IN  sys.AnyData);

Parameters

Table 88-14 PROCESS_RULES Procedure Parameters

Parameter Description

rule_class

The name of the rule class. A schema extended rule class name can be used to refer to a rule class that does not belong to the current schema.

event_inst

String or AnyData representation of the event instance being added to the rule class

event_type

Type of event instance assigned to the event_inst argument when the string representation of the event instance is used for a rule class configured for composite events


Usage Notes

Examples

The following command processes the rules in the TravelPromotion rule class for the given events.

BEGIN
  DBMS_RLMGR.PROCESS_RULES (
               rule_class => 'TravelPromotion',
               event_inst =>
                 AddFlight.getVarchar(987, 'Abcair', 'Boston', 'Orlando',
                                      '01-APR-2003', '08-APR-2003'));
END;

The following commands process the rules in the CompTravelPromo rule class for the two primitive events shown.

BEGIN  DBMS_RLMGR.PROCESS_RULES(
               rule_class => 'CompTravelPromo',
               event_inst =>
                 AddFlight.getVarchar(987, 'Abcair', 'Boston', 'Orlando',
                                      '01-APR-2003', '08-APR-2003'),
               event_type => 'AddFlight');
  DBMS_RLMGR.PROCESS_RULES(
               rule_class => 'Scott.CompTravelPromo',
               event_inst =>
                  AnyData.convertObject(AddRentalCar(987, 'Luxury', '03-APR-2003',
                                        '08-APR-2003', NULL)));
END;

RESET_SESSION Procedure

This procedure starts a new session and thus discards the results in the rule class results view.

Syntax

DBMS_RLMGR.RESET_SESSION  (
   rule_class  IN  VARCHAR2);

Parameters

Table 88-15 RESET_SESSION Procedure Parameter

Parameter Description

rule_class

The name of the rule class. A schema extended rule class name can be used to refer to a rule class that does not belong to the current schema.


Usage Notes

Examples

The following command resets a rule class session.

BEGIN  DBMS_RLMGR.RESET_SESSION(
             rule_class => 'CompTravelPromo');
END;

REVOKE_PRIVILEGE Procedure

This procedure revokes privileges on a rule class from another user.

Syntax

DBMS_RLMGR.REVOKE_PRIVILEGE  (
   rule_class      IN  VARCHAR2,
   priv_type       IN  VARCHAR2,
   from_user       IN  VARCHAR2);

Parameters

Table 88-16 REVOKE_PRIVILEGE Procedure Parameters

Parameter Description

rule_class

The name of the rule class in the current schema

priv_type

Type of rule class privilege to be revoked

from_user

The user from whom the privilege is to be revoked


Usage Notes

This procedure revokes appropriate privileges from a user. The types of privileges that can be revoked are the same as the types listed in the GRANT_PRIVILEGE Procedure description. Rule class privileges cannot be revoked from the owner of the rule class.

Examples

The following command revokes PROCESS RULES privilege on TravelPromo rule class from the user SCOTT.

BEGIN
  DBMS_RLMGR.REVOKE_PRIVILEGE(rule_class  => 'TravelPromo',
                              priv_type   => 'PROCESS RULES',
                              from_user   => 'SCOTT');
END;