home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / DBMSREPC.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  82.5 KB  |  1,786 lines

  1. rem 
  2. rem $Header: dbmsrepc.sql 7020200.1 95/02/15 18:31:13 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) Oracle Corporation 1994.  All Rights Reserved.
  5. Rem    NAME
  6. Rem      dbmsrepc.sql - replication catalog (repcat) packages
  7. Rem
  8. Rem    DESCRIPTION
  9. Rem      The following packages are located in this file:
  10. Rem        dbms_repcat - the main package, which is a cover for the 
  11. Rem                      implementation packages
  12. Rem        dbms_repcat_auth - avoid a clique of SYS links between masters
  13. Rem        dbms_repcat_admin - grant/revoke privileges to a replication
  14. Rem                            administrator to facilitate usage of repcat
  15. Rem
  16. Rem    NOTES
  17. Rem 
  18. Rem      The procedural option is needed to use this facility.
  19. Rem
  20. Rem      This packages are installed by sys (connect internal).
  21. Rem
  22. Rem      The repcat tables are defined in catrep.sql and owned by system.
  23. Rem
  24. Rem    DEPENDENCIES
  25. Rem      
  26. Rem    USAGE
  27. Rem
  28. Rem    SECURITY
  29. Rem
  30. Rem    MODIFIED   (MM/DD/YY)
  31. Rem     jstamos    01/21/95 -  merge changes from branch 1.1.710.11
  32. Rem     jstamos    12/20/94 -  merge changes from branch 1.1.710.7&8&9&10
  33. Rem     jstamos    11/11/94 -  merge changes from branch 1.1.710.6
  34. Rem     adowning   09/13/94 -  externalize conflict res error messages
  35. Rem     jstamos    09/01/94 -  externalize error messages
  36. Rem     jstamos    06/23/94 -  Add dbms_repcat_auth
  37. Rem     adowning   05/19/94 -  Make spec public
  38. Rem     adowning   02/04/94 -  Branch_for_patch
  39. Rem     adowning   02/04/94 -  Creation
  40. Rem
  41.  
  42. REM  ***********************************************************************
  43. REM  THESE PACKAGES AND PACKAGE BODIES MUST NOT BE MODIFIED BY THE CUSTOMER.
  44. REM  DOING SO COULD CAUSE INTERNAL ERRORS AND CORRUPTIONS IN THE RDBMS.
  45. REM  ***********************************************************************
  46.  
  47. REM  ************************************************************
  48. REM  THESE PACKAGES AND PACKAGE BODIES MUST BE CREATED UNDER SYS.
  49. REM  ************************************************************
  50.  
  51. CREATE OR REPLACE PACKAGE dbms_repcat AS
  52.  
  53.   -------------------------
  54.   -- OVERVIEW
  55.   --
  56.   -- This package provides routines to administer and update the replication
  57.   -- catalog.  An alternative would be to invent SQL DDL syntax.
  58.  
  59.   -----------
  60.   -- SECURITY
  61.   --
  62.  
  63.   --------
  64.   -- TYPES
  65.   --
  66.   -- allow room for quotes in columns
  67.   TYPE varchar2s IS TABLE OF VARCHAR(60) INDEX BY BINARY_INTEGER;
  68.  
  69.   ------------
  70.   -- CONSTANTS
  71.   --
  72.  
  73.   -------------
  74.   -- EXCEPTIONS
  75.   --
  76.   missingschema EXCEPTION;
  77.   PRAGMA exception_init(missingschema, -23306);
  78.   missschema_num NUMBER := -23306;
  79.  
  80.   duplicateschema EXCEPTION;
  81.   PRAGMA exception_init(duplicateschema, -23307);
  82.   duplschema_num NUMBER := -23307;
  83.  
  84.   missingobject EXCEPTION;
  85.   PRAGMA exception_init(missingobject, -23308);
  86.   missobj_num NUMBER := -23308;
  87.  
  88.   duplicateobject EXCEPTION;
  89.   PRAGMA exception_init(duplicateobject, -23309);
  90.   duplobj_num NUMBER := -23309;
  91.  
  92.   notquiesced EXCEPTION;
  93.   PRAGMA exception_init(notquiesced, -23310);
  94.   notquiesced_num NUMBER := -23310;
  95.  
  96.   notnormal EXCEPTION;
  97.   PRAGMA exception_init(notnormal, -23311);
  98.   notnormal_num NUMBER := -23311;
  99.  
  100.   nonmasterdef EXCEPTION;
  101.   PRAGMA exception_init(nonmasterdef, -23312);
  102.   nonmasterdef_num NUMBER := -23312;
  103.  
  104.   nonmaster EXCEPTION;
  105.   PRAGMA exception_init(nonmaster, -23313);
  106.   nonmaster_num NUMBER := -23313;
  107.  
  108.   nonsnapshot EXCEPTION;
  109.   PRAGMA exception_init(nonsnapshot, -23314);
  110.   nonsnapshot_num NUMBER := -23314;
  111.  
  112.   version EXCEPTION;
  113.   PRAGMA exception_init(version, -23315);
  114.   version_num NUMBER := -23315;
  115.  
  116.   reconfigerror EXCEPTION;
  117.   PRAGMA exception_init(reconfigerror, -23316);
  118.   reconfig_num NUMBER := -23316;
  119.  
  120.   commfailure EXCEPTION;
  121.   PRAGMA exception_init(commfailure, -23317);
  122.   commfail_num NUMBER := -23317;
  123.  
  124.   ddlfailure EXCEPTION;
  125.   PRAGMA exception_init(ddlfailure, -23318);
  126.   ddlfail_num NUMBER := -23318;
  127.  
  128.   typefailure EXCEPTION;
  129.   PRAGMA exception_init(typefailure, -23319);
  130.   typefail_num NUMBER := -23319;
  131.  
  132.   corrupt EXCEPTION;
  133.   PRAGMA exception_init(corrupt, -23320);
  134.   corrupt_num NUMBER := -23320;
  135.  
  136.   -- numbers 2321 to 2327 already used
  137.   badsnapname EXCEPTION;
  138.   PRAGMA exception_init(badsnapname, -23328);
  139.   badsnapname_num NUMBER := -23328;
  140.  
  141.   -- next available was 23353
  142.   fullqueue EXCEPTION;
  143.   PRAGMA exception_init(fullqueue, -23353);
  144.   fullqueue_num NUMBER := -23353;
  145.  
  146.   -- 
  147.   -- Conflict Resolution exceptions
  148.   --
  149.  
  150.   -- error message from deferred rpc applies equally well here
  151.   paramtype EXCEPTION;
  152.     PRAGMA exception_init(paramtype, -23325);
  153.     paramtype_num NUMBER := -23325;
  154.  
  155.   duplicategroup EXCEPTION;
  156.     PRAGMA exception_init(duplicategroup, -23330);
  157.     dupgrp_num NUMBER := -23330;
  158.    
  159.   missinggroup EXCEPTION;
  160.     PRAGMA exception_init(missinggroup, -23331);
  161.     missgrp_num NUMBER := -23331;
  162.    
  163.   referenced EXCEPTION;
  164.     PRAGMA exception_init(referenced, -23332);
  165.     ref_num NUMBER := -23332;
  166.   
  167.   duplicatecolumn EXCEPTION;
  168.     PRAGMA exception_init(duplicatecolumn, -23333);
  169.     dupcol_num NUMBER := -23333;
  170.   
  171.   missingcolumn EXCEPTION;
  172.     PRAGMA exception_init(missingcolumn, -23334);
  173.     misscol_num NUMBER := -23334;
  174.    
  175.   duplicateprioritygroup EXCEPTION;
  176.     PRAGMA exception_init(duplicateprioritygroup, -23335);
  177.     duppriorgrp_num NUMBER := -23335;
  178.    
  179.   missingprioritygroup EXCEPTION;
  180.     PRAGMA exception_init(missingprioritygroup, -23336);
  181.     misspriorgrp_num NUMBER := -23336;
  182.   
  183.   missingvalue EXCEPTION;
  184.     PRAGMA exception_init(missingvalue, -23337);
  185.     missval_num NUMBER := -23337;
  186.   
  187.   duplicatevalue EXCEPTION;
  188.     PRAGMA exception_init(duplicatevalue, -23338);
  189.     dupval_num NUMBER := -23338;
  190.   
  191.   duplicateresolution EXCEPTION;
  192.     PRAGMA exception_init(duplicateresolution, -23339);
  193.     dupres_num NUMBER := -23339;
  194.    
  195.   invalidmethod EXCEPTION;
  196.     PRAGMA exception_init(invalidmethod, -23340);
  197.     badmeth_num NUMBER := -23340;
  198.    
  199.   missingfunction EXCEPTION;
  200.     PRAGMA exception_init(missingfunction, -23341);
  201.     missfunc_num NUMBER := -23341;
  202.    
  203.   invalidparameter EXCEPTION;
  204.     PRAGMA exception_init(invalidparameter, -23342);
  205.     badparam_num NUMBER := -23342;
  206.    
  207.   missingresolution EXCEPTION;
  208.     PRAGMA exception_init(missingresolution, -23343);
  209.     missres_num NUMBER := -23343;
  210.   
  211.   missingconstraint EXCEPTION;
  212.     PRAGMA exception_init(missingconstraint, -23344);
  213.     missconst_num NUMBER := -23344;
  214.  
  215.   statnotreg  EXCEPTION;
  216.     PRAGMA exception_init(statnotreg, -23345);
  217.     statnotreg_num NUMBER := -23345;
  218.  
  219.   --
  220.   -- Offline instantiation exceptions
  221.   --
  222.  
  223.   oldglobalname EXCEPTION;
  224.     PRAGMA exception_init(oldglobalname, -23360);
  225.     oldglobal_num NUMBER := -23360;
  226.     oldglobal_msg VARCHAR2(76) := 'The Global Name is still the old name';
  227.  
  228.   missingremotesnap EXCEPTION;
  229.     PRAGMA execption_init(missingremotesnap, -23361);
  230.     misremsnap_num NUMBER := -23361;
  231.     misremsnap_msg VARCHAR2(76) := 'The remote snapshot does not exist';
  232.  
  233.   missingfromclause EXCEPTION;
  234.     PRAGMA execption_init(missingfromclause, -23362);
  235.     misfrom_num NUMBER := -23362;
  236.     misfrom_msg VARCHAR2(76) := 'From clause missing in the snapshot query';
  237.  
  238.   snaptabmismatch EXCEPTION;
  239.     PRAGMA execption_init(snaptabmismatch, -23363);
  240.     snaptabmis_num NUMBER := -23363;
  241.     snaptabmis_msg VARCHAR2(76) := 'Snapshot table name mismatch at two sites';
  242.  
  243.   --
  244.   -- Product factoring exceptions
  245.   --
  246.  
  247.   norepoption EXCEPTION;
  248.     PRAGMA execption_init(norepoption, -23364);
  249.     norepoption_num NUMBER := -23364;
  250.  
  251.   -------------
  252.   -- PROCEDURES
  253.   --
  254.  
  255.   PROCEDURE create_master_repschema(sname          IN VARCHAR2,
  256.                                     schema_comment IN VARCHAR2 := '',
  257.                                     master_comment IN VARCHAR2 := '');
  258.   -- Create a new, empty, quiesced master repschema, making the local database
  259.   -- the first replica and the masterdef.  The schema must already exist
  260.   -- locally as a database schems.
  261.   --
  262.   -- Exceptions:
  263.   --   duplicateschema if the schema already exists as a replicated schema.
  264.   --   missingschema if the schema does not exist.
  265.   --   ddlfailure if there is a problem creating the rep$what_am_i package
  266.   --     or package body.
  267.  
  268.   PROCEDURE add_master_database(sname                IN VARCHAR2,
  269.                                 master               IN VARCHAR2, 
  270.                                 use_existing_objects IN BOOLEAN := TRUE,
  271.                                 copy_rows            IN BOOLEAN := TRUE,
  272.                                 comment              IN VARCHAR2 := '');
  273.   -- The given master database is added to the given master repschema. The
  274.   -- new database is initialized with a consistent copy of all of the
  275.   -- contents of the repschema at the given host database. So that the host
  276.   -- database is consistent, all master repschema replicas must have been
  277.   -- quiesced with an earlier call to suspend_master_activity.
  278.   -- 
  279.   -- If a replicated object does not exist at the new master, the new
  280.   -- master creates the object.  If copy_rows is TRUE, then it copies any
  281.   -- contents from the masterdef site.
  282.   -- 
  283.   -- If a replicated object already exists at the new master, the situation
  284.   -- is more complicated.  If use_existing_objects is FALSE, or if the
  285.   -- object has the wrong type or "shape," the name conflict is recorded.
  286.   -- On the contrary, if the object has the right name, type, and "shape,"
  287.   -- and if use_existing_objects is TRUE, the object is reused.
  288.   -- If copy_rows is TRUE, the contents of the two objects are compared
  289.   -- piece by piece, and any discrepancies are rectified by using the
  290.   -- contents of the masterdef's object.  A probabilistic comparison
  291.   -- algorithm (such as one based on a checksum) may be used.  Such an
  292.   -- algorithm never states that two objects with identical contents are
  293.   -- different.
  294.   -- 
  295.   -- Because this procedure may use asynchronous activities, interim status
  296.   -- and all asynchronous errors are recorded in the RepCat log. If the
  297.   -- request completes successfully, the new master is added to all
  298.   -- RepSchema views, and no mention of the request appears in the RepCat
  299.   -- log.
  300.   -- 
  301.   -- Exceptions:
  302.   --
  303.   --   nonmasterdef if the invocation site is not the masterdef site.
  304.   --   notquiesced if the replicated schema has not been suspended.
  305.   --   duplicateschema if the schema already exists as a replicated schema at
  306.   --     the given database.
  307.   --   missingschema if the schema does not exist as a database schema at
  308.   --     the given database.
  309.   --   commfailure if the new master is not accessible.
  310.  
  311.   PROCEDURE remove_master_databases(sname       IN VARCHAR2,
  312.                                     master_list IN VARCHAR2);
  313.   -- To handle the case where several masters are inaccessible and must be
  314.   -- removed at one time, we provide a procedure that deletes a set of
  315.   -- masters. Master_list is a comma-separated list of masters.
  316.   -- Remove_master_databases does not require any removed database to be
  317.   -- accessible.  The other masters must be accessible.
  318.   -- 
  319.   -- For example, suppose A is the masterdef site and sites B, C, D, and E
  320.   -- are master sites for repschema R. If masters C and E become
  321.   -- inaccessible and should no longer be masters, the following should
  322.   -- be executed at site A:
  323.   -- 
  324.   --   -- remove C & E from RepSchema at A, B, & D
  325.   --   remove_master_databases(`R', `C,E');
  326.   -- 
  327.   -- Exceptions:
  328.   --   nonmasterdef if the invocation site is not the masterdef site.
  329.   --   nonmaster if any of the given databases is not a master site.
  330.   --   reconfigerror if any of the given databases is the masterdef site.
  331.   --   commfailure if any remaining master is not accessible.
  332.  
  333.   PROCEDURE remove_master_databases(sname        IN VARCHAR2,
  334.                                     master_table IN dbms_utility.dblink_array);
  335.   -- This overloads the preceding procedure and takes a table of masters
  336.   -- instead of a comma-separated list. The preceding example may also be
  337.   -- coded as follows:
  338.   -- 
  339.   -- master_table dbms_utility.dblink_array;
  340.   -- ...
  341.   -- master_table(1) := `C';
  342.   -- master_table(2) := `E';
  343.   -- remove_master_databases(`R', master_table);
  344.   -- 
  345.   -- Exceptions:
  346.   --   nonmasterdef if the invocation site is not the masterdef site.
  347.   --   nonmaster if any of the given databases is not a master site.
  348.   --   reconfigerror if any of the given databases is the masterdef site.
  349.   --   commfailure if any remaining master is not accessible.
  350.  
  351.   PROCEDURE create_master_repobject(sname               IN VARCHAR2,
  352.                                     oname               IN VARCHAR2,
  353.                                     type                IN VARCHAR2,
  354.                                     use_existing_object IN BOOLEAN := TRUE,
  355.                                     ddl_text            IN VARCHAR2 := NULL,
  356.                                     comment             IN VARCHAR2 := '',
  357.                                     retry               IN BOOLEAN := FALSE,
  358.                                     copy_rows           IN BOOLEAN := TRUE);
  359.   -- This procedure, which typically operates in an asynchronous fashion,
  360.   -- requires that the replicated schema be quiesced with
  361.   -- suspend_master_activity. It adds the given object name and type to the
  362.   -- RepObject view at each repschema site. It optionally uses the given
  363.   -- DDL text to create the object at the masterdef site. If no DDL text is
  364.   -- given, the object must already exist at the masterdef site.  If retry
  365.   -- is TRUE, it creates the object only at masters whose object status is
  366.   -- not 'valid'.
  367.   -- 
  368.   -- If the object does not exist at a non-masterdef site, the site creates
  369.   -- the object.  If copy_rows is TRUE, it then copies any contents from the
  370.   -- masterdef site.
  371.   -- 
  372.   -- If the object already exists at a non-masterdef site, the situation is
  373.   -- more complicated.  If use_existing_object is FALSE, or if the object has
  374.   -- the wrong type or "shape," a duplicateobject exception is stored in the
  375.   -- RepCat log. On the contrary, if the object has the right name, type,
  376.   -- and "shape," and if use_existing_object is TRUE, the object is reused.
  377.   -- If copy_rows is TRUE, the contents of the two objects are
  378.   -- (probabilistically) compared piece by piece and any discrepancies are
  379.   -- rectified by using the contents of the masterdef's object.
  380.   -- 
  381.   -- The RepCat log contains interim status and any asynchronous error
  382.   -- messages generated by the request.
  383.   -- 
  384.   -- Exceptions:
  385.   --   nonmasterdef if the invocation site is not the masterdef site.
  386.   --   notquiesced if the replicated schema has not been suspended.
  387.   --   duplicateobject if the given object already exists in the repschema
  388.   --     and retry is FALSE, or if a name conflict occurs.
  389.   --   missingobject if the given object does not exist and no DDL text is
  390.   --     given, or if oname directly or indirectly refers to a remote object.
  391.   --   typefailure if objects of the given type can not be replicated.
  392.   --   ddlfailure if any DDL at the masterdef does not succeed.
  393.   --   commfailure if any master is not accessible.
  394.  
  395.   PROCEDURE set_columns(sname       IN VARCHAR2,
  396.                         oname       IN VARCHAR2,
  397.                         column_list IN VARCHAR2);
  398.   -- If oname exists in the replicated schema as a table using column-level
  399.   -- replication, record the set of columns to be used as the "primary key"
  400.   -- for replication purposes.  Unlike true primary keys, these columns may
  401.   -- contain NULLS.  The column_list parameter is a comma-separated list of
  402.   -- column names.  Set_columns does not affect the generated PL/SQL until
  403.   -- the next call to generate_replication_support on the given object.
  404.   --
  405.   -- Exceptions:
  406.   --  nonmasterdef if the invocation site is not the masterdef site.
  407.   --  missingobject if the given object does not exist as a table in the
  408.   --    replicated schema awaiting column-level replication information.
  409.   --  missingcolumn if any column is not in the table.
  410.  
  411.   PROCEDURE set_columns(sname        IN VARCHAR2,
  412.                         oname        IN VARCHAR2,
  413.                         column_table IN dbms_utility.name_array);
  414.   -- This overloads the preceding procedure and takes a table of column names.
  415.  
  416.   PROCEDURE generate_replication_support(sname            IN VARCHAR2,
  417.                                          oname            IN VARCHAR2,
  418.                                          type             IN VARCHAR2,
  419.                                          package_prefix   IN VARCHAR2 := NULL,
  420.                                          procedure_prefix IN VARCHAR2 := NULL,
  421.                                          distributed      IN BOOLEAN := FALSE);
  422.   -- If the object exists in the replicated schema as a table using
  423.   -- row/column-level replication, generate the row-level replication trigger
  424.   -- and stored package. When row-level or column-level replication is used for
  425.   -- an object, generate_replication_support should be called immediately after
  426.   -- all calls to set_columns.
  427.   --
  428.   -- If the object exists in the replicated schema as a procedure, 
  429.   -- generate the procedure wrapper using the given
  430.   -- procedure prefix.  If the object exists in the replicated schema as a
  431.   -- package (body), generate the procedure wrappers
  432.   -- using the given package and procedure prefixes.  In either case
  433.   -- generate_replication_support should be called immediately after
  434.   -- create_master_repobject or alter_master_repobject.
  435.   --
  436.   -- If distributed is TRUE, invoke the replication generator at each master.
  437.   -- Otherwise, invoke it once at the masterdef and copy the results.
  438.   --
  439.   -- Exceptions:
  440.   --   nonmasterdef if the invocation site is not the masterdef site.
  441.   --   missingobject if the given object does not exist as a table in the
  442.   --     replicated schema awaiting row/column-level replication information
  443.   --     or as a procedure or package (body) awaiting wrapper generation.
  444.   --   typefailure if the given type parameter is not supported.
  445.   --   notquiesced if the replicated schema has not been suspended.
  446.   --   commfailure if any master is not accessible.
  447.  
  448.   PROCEDURE alter_master_repobject(sname    IN VARCHAR2,
  449.                                    oname    IN VARCHAR2, 
  450.                                    type     IN VARCHAR2,
  451.                                    ddl_text IN VARCHAR2,
  452.                                    comment  IN VARCHAR2 := '',
  453.                                    retry    IN BOOLEAN := FALSE);
  454.   -- This procedure, which typically operates in an asynchronous fashion,
  455.   -- requires that the replicated schema be quiesced with
  456.   -- suspend_master_activity. The DDL is applied at the masterdef and is
  457.   -- synchronously multicast to all masters. Each master (asynchronously)
  458.   -- checks that the object exists locally and then applies the DDL to its
  459.   -- replica.  If comment is not NULL, then each altered object's comment
  460.   -- is updated.  If retry is TRUE, alter_master_repobject alters
  461.   -- the object only at masters whose object status is not 'valid'.
  462.   -- The RepCat log contains interim status and any asynchronous
  463.   -- error messages generated by the request.
  464.   -- 
  465.   -- Local customization of individual replicas is outside the
  466.   -- scope of RepCat.  Replication administrators should ensure that local
  467.   -- customizations do not interfere with the global customizations done
  468.   -- with alter_master_repobject. 
  469.   -- 
  470.   -- Exceptions:
  471.   --   nonmasterdef if the invocation site is not the masterdef site.
  472.   --   notquiesced if the replicated schema has not been suspended.
  473.   --   missingobject if the given object does not exist.
  474.   --   typefailure if the given type parameter is not supported.
  475.   --   ddlfailure if any DDL at the masterdef does not succeed.
  476.   --   commfailure if a master is not accessible.
  477.  
  478.   PROCEDURE drop_master_repobject(sname        IN VARCHAR2,
  479.                                   oname        IN VARCHAR2, 
  480.                                   type         IN VARCHAR2, 
  481.                                   drop_objects IN BOOLEAN := FALSE);
  482.   -- This procedure typically operates in an asynchronous fashion. It
  483.   -- removes the given object name from the RepObject view at all sites,
  484.   -- and optionally drops the object and dependent objects at all sites.
  485.   -- The RepCat log contains interim status and any asynchronous error
  486.   -- messages generated by the request.
  487.   -- 
  488.   -- Exceptions:
  489.   --   nonmasterdef if the invocation site is not the masterdef site.
  490.   --   missingobject if the given object does not exist.
  491.   --   typefailure if the given type parameter is not supported.
  492.   --   commfailure if a master is not accessible.
  493.  
  494.   PROCEDURE execute_DDL(sname       IN VARCHAR2,
  495.                         master_list IN VARCHAR2 := NULL,
  496.                         ddl_text    IN VARCHAR2);
  497.   -- Master_list is a comma-separated list of masters. If NULL, it means
  498.   -- all masters including the masterdef. The DDL is applied at the given
  499.   -- set of masters. This is typically done asynchronously. The RepCat log
  500.   -- contains interim status and any asynchronous error messages generated
  501.   -- by the request.  Although the repschema need not be quiesced when
  502.   -- execute_DDL is invoked, an administrator may quiesce the schema first.
  503.   -- 
  504.   -- Exceptions:
  505.   --   nonmasterdef if the invocation site is not the masterdef site.
  506.   --   nonmaster if any site is not a master.
  507.   --   ddlfailure if any DDL at the masterdef does not succeed.
  508.   --   commfailure if a master is not accessible.
  509.  
  510.   PROCEDURE execute_DDL(sname        IN VARCHAR2,
  511.                         master_table IN dbms_utility.dblink_array,
  512.                         ddl_text     IN VARCHAR2);
  513.   -- This overloads the preceding procedure and takes a table of masters
  514.   -- instead of a comma-separated list.
  515.   -- 
  516.   -- Exceptions:
  517.   --   nonmasterdef if the invocation site is not the masterdef site.
  518.   --   nonmaster if any site is not a master.
  519.   --   ddlfailure if any DDL at the masterdef does not succeed.
  520.   --   commfailure if a master is not accessible.
  521.  
  522.   PROCEDURE comment_on_repcat(sname   IN VARCHAR2,
  523.                               comment IN VARCHAR2);
  524.   -- Update the comment field for the given repschema in RepCat.
  525.   --
  526.   -- Exceptions:
  527.   --
  528.   --  nonmasterdef if the invocation site is not the masterdef site.
  529.   --  commfailure if any master is not accessible.
  530.  
  531.   PROCEDURE comment_on_repobject(sname   IN VARCHAR2,
  532.                                  oname   IN VARCHAR2,
  533.                                  type    IN VARCHAR2,
  534.                                  comment IN VARCHAR2);
  535.   -- Update the comment field for the given repobject in RepObject.
  536.   --
  537.   -- Exceptions:
  538.   --
  539.   --  nonmasterdef if the invocation site is not the masterdef site.
  540.   --  missingobject if the given object does not exist.
  541.   --  typefailure if the given type parameter is not supported.
  542.   --  commfailure if any master is not accessible.
  543.  
  544.   PROCEDURE comment_on_repschema(sname   IN VARCHAR2,
  545.                                  master  IN VARCHAR,
  546.                                  comment IN VARCHAR2);
  547.   -- Update the comment field for the given master in RepSchema.
  548.   --
  549.   -- Exceptions:
  550.   --
  551.   --  nonmasterdef if the invocation site is not the masterdef site.
  552.   --  nonmaster if the given master is not a master.
  553.   --  commfailure if any master is not accessible.
  554.  
  555.   PROCEDURE suspend_master_activity(sname IN VARCHAR2);
  556.   -- The replicated schema must be in normal operation when this procedure
  557.   -- is called. It quiesces all activity at all master repschema sites,
  558.   -- disables deferred procedure calls, and processes all pending queued
  559.   -- procedure calls. Each master remains in this state until
  560.   -- resume_master_activity is invoked.
  561.   -- 
  562.   -- Several of the above administrative procedures (e.g. adding a master
  563.   -- database) must first suspend activity. Administrators may wish to
  564.   -- suspend activity and manually perform a distributed query and update
  565.   -- on the replicas in order to restore equivalence in the event of an
  566.   -- errant conflict resolution.
  567.   -- 
  568.   -- This procedure typically operates asynchronously at the masterdef and
  569.   -- the masters. The RepCat log contains interim status.
  570.   -- 
  571.   -- Exceptions:
  572.   --   nonmasterdef if the invocation site is not the masterdef site.
  573.   --   notnormal if the replicated schema is not in normal operation.
  574.   --   commfailure if any master is not accessible.
  575.  
  576.   PROCEDURE resume_master_activity(sname    IN VARCHAR2,
  577.                                    override IN BOOLEAN := FALSE);
  578.   -- The replicated schema must be quiescing or quiesced when this
  579.   -- procedure is called. If override is TRUE, it ignores any pending
  580.   -- RepCat administration requests and restores normal replication
  581.   -- activity at each master as quickly as possible. If override is FALSE,
  582.   -- it restores normal replication activity at each master only when there
  583.   -- is no pending RepCat administration request for sname at that
  584.   -- master.
  585.   -- 
  586.   -- Exceptions:
  587.   --   nonmasterdef if the invocation site is not the masterdef site.
  588.   --   notquiesced if the replicated schema is not quiescing or quiesced.
  589.   --   commfailure if any master is not accessible.
  590.  
  591.   PROCEDURE drop_master_repschema(sname         IN VARCHAR2,
  592.                                   drop_contents IN BOOLEAN := FALSE,
  593.                                   all_sites     IN BOOLEAN := FALSE);
  594.   -- Drop the master repschema and optionally all of its contents. If
  595.   -- all_sites is TRUE and the invocation site is the masterdef,
  596.   -- synchronously multicast the request to all masters.  In this case
  597.   -- execution is immediate at the masterdef and possibly deferred at all
  598.   -- other master sites. Note that this procedure may leave some dangling
  599.   -- snapshot repschemas.
  600.   -- 
  601.   -- Exceptions:
  602.   --   nonmaster if the invocation site is not a master site.
  603.   --   nonmasterdef if the invocation site is not the masterdef and all_sites
  604.   --     is TRUE.
  605.   --   fullqueue if the deferred RPC queue has entries for the repschema.
  606.   --   commfailure if a master is not accessible and all_sites is TRUE.
  607.  
  608.   PROCEDURE relocate_masterdef(sname                 IN VARCHAR2,
  609.                                old_masterdef         IN VARCHAR2, 
  610.                                new_masterdef         IN VARCHAR2,
  611.                                notify_masters        IN BOOLEAN := TRUE, 
  612.                                include_old_masterdef IN BOOLEAN := TRUE);
  613.   -- Move the masterdef designation from old_masterdef to new_masterdef.
  614.   -- Old_masterdef must be the current masterdef, and new_masterdef must be
  615.   -- a master. If notify_masters is TRUE, sychronously multicast the change
  616.   -- to all masters (including old_masterdef only if include_old_masterdef
  617.   -- is TRUE). If any master does not make the change, rollback the changes
  618.   -- at all masters.
  619.   -- 
  620.   -- In a planned reconfiguration, relocate_masterdef should be invoked
  621.   -- with notify_masters TRUE and include_old_masterdef TRUE. If just the
  622.   -- masterdef fails, relocate_masterdef should be invoked with
  623.   -- notify_masters TRUE and include_old_masterdef FALSE. If several
  624.   -- masters and the masterdef fail, the administrator should invoke
  625.   -- relocate_masterdef at each operational master with notify_masters FALSE.
  626.   -- 
  627.   -- Exceptions:
  628.   --   nonmaster if new_masterdef is not a master site or if the invocation
  629.   --     site is not a master site.
  630.   --   nonmasterdef if old_masterdef is not the masterdef site.
  631.   --   commfailure if a master is not accessible and notify_masters is TRUE.
  632.  
  633.   PROCEDURE purge_master_log(id     IN NATURAL,
  634.                              source IN VARCHAR2,
  635.                              sname  IN VARCHAR2);
  636.   -- Remove all local log records corresponding to the request on a given
  637.   -- replicated schema that originated at the given master with the given
  638.   -- identification. If any parameter is NULL, treat it as a wildcard.
  639.   -- 
  640.   -- Exceptions:
  641.   --   nonmaster if sname is not NULL and the invocation site is not a
  642.   --     master site.
  643.  
  644.   PROCEDURE wait_master_log(sname        IN  VARCHAR2,
  645.                             record_count IN  NATURAL,
  646.                             timeout      IN  NATURAL,
  647.                             true_count   OUT NATURAL);
  648.   -- Wait until either timeout seconds have passed or there are at most
  649.   -- record_count records in the local RepCat log that represent administrative
  650.   -- activities for the given replicated schema that have not completed.
  651.   -- Activities that have completed with or without an error are not
  652.   -- considered. The number of incomplete activities is returned in the
  653.   -- parameter true_count.
  654.   -- 
  655.   -- If there are N masters and 1 masterdef for a replicated schema, most
  656.   -- asynchronous administrative requests eventually create N+1 log records
  657.   -- at the masterdef and 1 log record at each master.  Add_master_database
  658.   -- is an exception and may create a log record at the masterdef and a log
  659.   -- record at the new master for each object in the replicated schema.
  660.   -- 
  661.   -- Exceptions:
  662.   --   nonmaster if the invocation site is not a master site.
  663.  
  664.   PROCEDURE do_deferred_repcat_admin(sname     IN VARCHAR2,
  665.                                      all_sites IN BOOLEAN := FALSE);
  666.   -- Execute local outstanding deferred administrative procedures for the
  667.   -- given replicated schema requested by the current user.  If all_sites
  668.   -- is TRUE, do this at each master.
  669.   -- 
  670.   -- Exceptions:
  671.   --   nonmaster if the invocation site is not a master site.
  672.   --   commfailure if a master is not accessible and all_sites is TRUE.
  673.  
  674.   PROCEDURE repcat_import_check(sname  IN VARCHAR2,
  675.                                 master IN BOOLEAN);
  676.   -- Update the object identifiers and status values in repcat$_repobject
  677.   -- for the given schema, preserving object status values other than VALID.
  678.   --
  679.   -- Exceptions:
  680.   --   missingschema if the replicated schema does not exist.
  681.   --   nonmaster if master is TRUE and either the database is not a master or
  682.   --      the database is not the expected database.
  683.   --   nonsnapshot if master is FALSE and the database is not a snapshot site.
  684.   --   missingobject if a valid replicated object in the schema does not exist.
  685.  
  686.   PROCEDURE repcat_import_check;
  687.   -- Invoke repcat_import_check(sname) on each replicated schema
  688.   --
  689.   -- Exceptions:
  690.   --   nonmaster if the database is not the expected database for any
  691.   --     replicated schema.
  692.   --   missingobject if a valid replicated object in any schema does not exist.
  693.  
  694.   PROCEDURE create_snapshot_repschema(sname   IN VARCHAR2,
  695.                                       master  IN VARCHAR2,
  696.                                       comment IN VARCHAR2 := '');
  697.   -- Create a new empty snapshot repschema and make the given database the
  698.   -- master. The schema name must be a master repschema at the master
  699.   -- database.  In addition, the schema must also exist locally as a database
  700.   -- schema.
  701.   -- 
  702.   -- Exceptions:
  703.   --   duplicateschema if the schema already exists as a replicated schema
  704.   --     at the invocation site.
  705.   --   nonmaster if the given database is not a master site.
  706.   --   commfailure if the given database is not accessible.
  707.  
  708.   PROCEDURE drop_snapshot_repschema(sname         IN VARCHAR2,
  709.                                     drop_contents IN BOOLEAN := FALSE);
  710.   -- Drop the given snapshot repschema and optionally all of its contents
  711.   -- at this snapshot site.
  712.   -- 
  713.   -- Exceptions:
  714.   --   nonsnapshot if the invocation site is not a snapshot site.
  715.  
  716.   PROCEDURE refresh_snapshot_repschema(sname                 IN VARCHAR2,
  717.                                        drop_missing_contents IN BOOLEAN
  718.                                          := FALSE,
  719.                                        refresh_snapshots     IN BOOLEAN
  720.                                          := FALSE,
  721.                                        refresh_other_objects IN BOOLEAN
  722.                                          := FALSE);
  723.   -- Refresh the RepCat views for the given repschema and optionally drop
  724.   -- objects no longer in the repschema.  Consistently refresh the snapshots
  725.   -- iff refresh_snapshots is TRUE.  Refresh the other objects if
  726.   -- refresh_other_objects is TRUE.
  727.   -- 
  728.   -- Exceptions:
  729.   --   nonsnapshot if the invocation site is not a snapshot site.
  730.   --   nonmaster if the master is no longer a master site.
  731.   --   commfailure if the master is not accessible.
  732.  
  733.   PROCEDURE switch_snapshot_master(sname  IN VARCHAR2,
  734.                                    master IN VARCHAR2);
  735.   -- Change the master database of the snapshot repschema to the given
  736.   -- database. The new database must contain a replica of the master
  737.   -- repschema. Each snapshot in the local repschema will be completely
  738.   -- refreshed from the new master the next time it is refreshed.
  739.   -- Will not work if snapshot query is > 32 K.
  740.   -- 
  741.   -- Any snapshot logs should be created at all masters to avoid future 
  742.   -- complete refreshes.
  743.   --
  744.   -- During creation, Snapshots names & onames should be the same.  
  745.   -- Also, masters in snapshot defs should match repschema's snapshot master.
  746.   -- 
  747.   -- Exceptions:
  748.   --   nonsnapshot if the invocation site is not a snapshot site.
  749.   --   nonmaster if the given database is not a master site.
  750.   --   commfailure if the given database is not accessible.
  751.  
  752.   PROCEDURE create_snapshot_repobject(sname    IN VARCHAR2,
  753.                                       oname    IN VARCHAR2,
  754.                                       type     IN VARCHAR2,
  755.                                       ddl_text IN VARCHAR2 := '',
  756.                                       comment  IN VARCHAR2 := '');
  757.   -- Add the given object name and type to the RepObject view at the local
  758.   -- snapshot repschema. The allowed types are `package', `package body',
  759.   -- 'procedure', `snapshot', `synonym', and `view'.
  760.   -- 
  761.   -- For objects of type `snapshot', copy the row-level replication trigger
  762.   -- and client-side half of the stored package if the underlying table
  763.   -- uses row/column-level replication.  
  764.   -- 
  765.   -- ddl_text defines the snapshots.  The oname should match the snapshot
  766.   -- name defined in the ddl_text.  The snaphot's master should match the
  767.   -- master stored in all_repschema (for switch_snapshot_masters to work).
  768.   -- 
  769.   -- Exceptions:
  770.   --   nonsnapshot if the invocation site is not a snapshot site.
  771.   --   nonmaster if the master is no longer a master site.
  772.   --   missingobject if the given object does not exist in the master's
  773.   --     replicated schema.
  774.   --   duplicateobject if the given object already exists.
  775.   --   typefailure if the type is not an allowable type.
  776.   --   ddlfailure if the DDL does not succeed.
  777.   --   commfailure if the master is not accessible.
  778.  
  779.   PROCEDURE drop_snapshot_repobject(sname        IN VARCHAR2,
  780.                                     oname        IN VARCHAR2, 
  781.                                     type         IN VARCHAR2, 
  782.                                     drop_objects IN BOOLEAN := FALSE);
  783.   -- Remove the given object name from the local snapshot RepObject view,
  784.   -- and optionally drop the object and dependent objects.
  785.   -- 
  786.   -- Exceptions:
  787.   --   nonsnapshot if the invocation site is not a snapshot site.
  788.   --   missingobject if the given object does not exist.
  789.   --   typefailure if the given type parameter is not supported.
  790.  
  791.   PROCEDURE tickle_job(canon_sname IN VARCHAR2,
  792.                        start_now   IN BOOLEAN := FALSE);
  793.   -- Start the background job for processing the user's repcatlog records,
  794.   -- creating the job if necessary.  This procedure is normally called by
  795.   -- repcat executing as the user, and is here only for privilege reasons.
  796.  
  797.   -------------
  798.   -- CONFLICT RESOLUTION PROCEDURES
  799.   --
  800.   -- The following procedures are added to support automatic conflict 
  801.   -- resolution.  Note that these procedures are available only on master 
  802.   -- sites.  Conflict resolution is not available on snapshot sites.
  803.  
  804.  PROCEDURE define_column_group(sname IN VARCHAR2, 
  805.                                oname IN VARCHAR2, 
  806.                                column_group IN VARCHAR2, 
  807.                                comment IN VARCHAR2 := NULL);
  808.   -- Create a new column group for the given repobject.  Define_column_group 
  809.   -- does not affect the generated PL/SQL until the next call to 
  810.   --  generate_replication_support.
  811.   --
  812.   -- Input Parameters:
  813.   --    sname: The name of the schema containing the table to be replicated.  
  814.   --           Defaults to invoking user. 
  815.   --    oname: The name of the table being replicated.
  816.   --    column_group: The name of the column group being defined. 
  817.   --    comment: Comment text for the column group being defined. 
  818.   -- Exceptions:
  819.   --    nonmasterdef: if the invocation site is not the masterdef site.
  820.   --    duplicategroup: if the given column group already exists for the 
  821.   --                    repobject.
  822.   --    missingobject: if the given repobject does not exist.
  823.  
  824.   PROCEDURE comment_on_column_group(sname IN VARCHAR2, 
  825.                                     oname IN VARCHAR2, 
  826.                                     column_group IN VARCHAR2, 
  827.                                     comment IN VARCHAR2);
  828.  
  829.   -- Update the comment field for the given column group.
  830.   -- Input Parameters:
  831.   --    sname: The name of the schema containing the table to be replicated.  
  832.   --           Defaults to invoking user. 
  833.   --    oname: The name of the table being replicated.
  834.   --    column_group: The name of the column group.
  835.   --    comment: Comment text for the column group being defined. 
  836.   -- Exceptions:
  837.   --    nonmasterdef: if the invocation site is not the masterdef site.
  838.   --    missinggroup: if the given column group does not exist.
  839.  
  840.   PROCEDURE drop_column_group(sname IN VARCHAR2, 
  841.                               oname IN VARCHAR2, 
  842.                               column_group IN VARCHAR2);
  843.   -- Drop the given column group.  Drop_column_group does not affect the 
  844.   -- PL/SQL until the next call to generate_replication_support.
  845.   -- Input Parameters:
  846.   --    sname: The name of the schema containing the table to be replicated.  
  847.   --           Defaults to invoking user.
  848.   --    oname: The name of the table being replicated.
  849.   --    column_group: The name of the column group.
  850.   -- Exceptions:
  851.   --    nonmasterdef: if the invocation site is not the masterdef site.
  852.   --    referenced: if the given column group is being used in conflict 
  853.   --                detection and resolution.
  854.  
  855.   PROCEDURE add_grouped_column(sname IN VARCHAR2,
  856.                                oname IN VARCHAR2,
  857.                                column_group IN VARCHAR2,
  858.                                list_of_column_names IN VARCHAR2);
  859.   PROCEDURE add_grouped_column(sname IN VARCHAR2, 
  860.                                oname IN VARCHAR2,
  861.                                column_group IN VARCHAR2,
  862.                                list_of_column_names IN dbms_repcat.varchar2s);
  863.   -- Assign a set of columns to the given column group.  Add_grouped_column 
  864.   -- does not affect the generated PL/SQL until the next call to 
  865.   -- generate_replication_support.
  866.   -- Input Parameters:
  867.   --    sname: The name of the schema containing the table to be replicated.
  868.   --           Defaults to invoking user.
  869.   --    oname: The name of the table being replicated.
  870.   --    column_group: The name of the column group.
  871.   --    list_of_column_names: A list of columns being added to the column .
  872.   --            group. The list can be a comma separated list of columns or
  873.   --            a pl/sql table of columns.
  874.   --            a '*' as the only entry in the list results in all the
  875.   --            columns in the table being entered as part of the column group 
  876.   -- Exceptions:
  877.   --    nonmasterdef: if the invocation site is not the masterdef site.
  878.   --    duplicatecolumn: if the given column already exists in the column group.
  879.   --    missinggroup: if the given column group does not exist.
  880.   --    missingcolumn: if the given column does not exist in the repobject.
  881.   PROCEDURE make_column_group (sname IN VARCHAR2,
  882.                                oname IN VARCHAR2,
  883.                                column_group IN VARCHAR2,
  884.                                list_of_column_names IN VARCHAR2);
  885.   PROCEDURE make_column_group (sname IN VARCHAR2, 
  886.                                oname IN VARCHAR2,
  887.                                column_group IN VARCHAR2,
  888.                                list_of_column_names 
  889.                                             IN dbms_repcat.varchar2s);
  890.   -- do a combined define & add
  891.  
  892.   PROCEDURE drop_grouped_column(sname IN VARCHAR2,
  893.                                 oname IN VARCHAR2,
  894.                                 column_group IN VARCHAR2,
  895.                                 list_of_column_names 
  896.                                             IN dbms_repcat.varchar2s);
  897.  
  898.   PROCEDURE drop_grouped_column(sname IN VARCHAR2,
  899.                                 oname IN VARCHAR2,
  900.                                 column_group IN VARCHAR2,
  901.                                 list_of_column_names IN VARCHAR2);
  902.   -- Remove a column from the given column group.  Drop_grouped_column does not 
  903.   -- affect the generated PL/SQL until the next call to 
  904.   -- generate_replication_support.
  905.   -- Input Parameters:
  906.   --    sname: The name of the schema containing the table to be replicated.
  907.   --           Defaults to invoking user.
  908.   --    oname: The name of the table being replicated.
  909.   --    column_group: The name of the column group.
  910.   --    column_name: The name of  the column being added to the column group.
  911.   -- Exceptions:
  912.   --    nonmasterdef: if the invocation site is not the masterdef site.
  913.   --    missinggroup: if the given column group does not exist.
  914.  
  915.   PROCEDURE define_priority_group(sname IN VARCHAR2,
  916.                                   pgroup IN VARCHAR2,
  917.                                   datatype IN VARCHAR2,
  918.                                   fixed_length IN INTEGER := NULL,
  919.                                   comment IN VARCHAR2 := NULL);
  920.   -- Create a new priority group.  The name of the priority group must be 
  921.   -- unique in a repschema.  The valid values of datatype are those, except 
  922.   -- rowid, that are supported by Rep2.  Define_priority_group does not affect 
  923.   -- the generated PL/SQL until the next call to generate_replication_support.  
  924.   -- Input Parameters:
  925.   --    sname: The name of the schema containing the table to be replicated.  
  926.   --           Defaults to invoking user. 
  927.   --    pgroup: The name of the priority group being created.
  928.   --    datatype: The datatype of value in the priority group being created.  
  929.   --            Supported datatypes are: `CHAR', `VARCHAR2', `NUMBER', `DATE', 
  930.   --            and `RAW'. 
  931.   --    fixed_length: The fixed length for data of type CHAR.  
  932.   --    comment: Comment text for the priority group being created.
  933.   -- Exceptions:
  934.   --    nonmasterdef: if the invocation site is not the masterdef site.
  935.   --    missingschema: if the given repschema does not exist.
  936.   --    duplicateprioritygroup: if the given priority group already exists 
  937.   --             in the repschema.
  938.   --    typefailure: if the given datatype is not an allowable type.
  939.  
  940.   PROCEDURE comment_on_priority_group(sname IN VARCHAR2,
  941.                                       pgroup IN VARCHAR2, 
  942.                                       comment IN VARCHAR2);
  943.   -- Update the comment field for the given priority group.
  944.   -- Input Parameters:
  945.   --    sname: The name of the schema containing the table to be replicated.  
  946.   --           Defaults to invoking user. 
  947.   --    pgroup: The name of the priority group.
  948.   --    comment: Comment text for the priority group being created.
  949.   -- Exceptions:
  950.   --    nonmasterdef: if the invocation site is not the masterdef site.
  951.   --    missingprioritygroup: if the given priority group does not exist.
  952.  
  953.   PROCEDURE drop_priority_group(sname IN VARCHAR2,
  954.                                 pgroup in VARCHAR2);
  955.   -- Drop the given priority group.  Drop_priority_group does not affect the 
  956.   -- generated PL/SQL until the next call to generate_replication_support.  
  957.   -- Users cannot drop a priority group if the priority group is still 
  958.   -- referenced in any generated resolution packages.
  959.   -- Input Parameters:
  960.   --    sname: The name of the schema containing the table to be replicated.  
  961.   --           Defaults to invoking user. 
  962.   --    pgroup: The name of the priority group.
  963.   -- Exceptions:
  964.   --    nonmasterdef: if the invocation site is not the masterdef site.
  965.   --    referenced: if the given priority group is being used in conflict 
  966.   --           resolution.
  967.  
  968.   PROCEDURE add_priority_char(sname in VARCHAR2,
  969.                               pgroup IN VARCHAR2,
  970.                               value IN CHAR,
  971.                               priority IN NUMBER);
  972.   PROCEDURE add_priority_varchar2(sname in VARCHAR2,
  973.                                   pgroup IN VARCHAR2,
  974.                                   value IN VARCHAR2,
  975.                                   priority IN NUMBER);
  976.   PROCEDURE add_priority_number(sname in VARCHAR2,
  977.                                 pgroup IN VARCHAR2, 
  978.                                 value IN NUMBER,
  979.                                 priority IN NUMBER);
  980.   PROCEDURE add_priority_date(sname in VARCHAR2,
  981.                               pgroup IN VARCHAR2,
  982.                               value IN DATE,
  983.                               priority IN NUMBER);
  984.   PROCEDURE add_priority_raw(sname in VARCHAR2,
  985.                              pgroup IN VARCHAR2,
  986.                              value IN RAW,
  987.                              priority IN NUMBER);
  988.   -- Add a new value to the given priority group.  The new value
  989.   -- must be unique, and the priority must be unique.  The addition of this
  990.   -- value becomes effective immediately.
  991.   -- Input Parameters:
  992.   --    sname: The name of the schema containing the table to be replicated.
  993.   --           Defaults to invoking user.
  994.   --    pgroup: The name of the priority group.
  995.   --    value: A new value for the priority group.
  996.   --    priority: The priority for the new value.
  997.   -- Exceptions:
  998.   --    nonmasterdef: if the invocation site is not the masterdef site.
  999.   --    duplicatevalue: if the given value already exists in the priority group.
  1000.   --    duplicatepriority: if the given priority already exists in the priority 
  1001.   --           group.
  1002.   --    missingprioritygroup: if the given priority group does not exist.
  1003.   --    typefailure: if the given value has an incorrect datatype for the
  1004.   --           priority group.
  1005.  
  1006.   PROCEDURE alter_priority_char(sname in VARCHAR2,
  1007.                                 pgroup IN VARCHAR2,
  1008.                                 old_value IN CHAR,
  1009.                                 new_value IN CHAR);
  1010.   PROCEDURE alter_priority_varchar2(sname in VARCHAR2,
  1011.                                     pgroup IN VARCHAR2,
  1012.                                     old_value IN VARCHAR2,
  1013.                                     new_value IN VARCHAR2);
  1014.   PROCEDURE alter_priority_number(  sname in VARCHAR2,
  1015.                                     pgroup IN VARCHAR2,
  1016.                                     old_value IN NUMBER,
  1017.                                     new_value IN NUMBER);
  1018.   PROCEDURE alter_priority_raw(     sname in VARCHAR2,
  1019.                                     pgroup IN VARCHAR2,
  1020.                                     old_value IN RAW,
  1021.                                     new_value IN RAW);
  1022.   PROCEDURE alter_priority_date(    sname in VARCHAR2,
  1023.                                     pgroup IN VARCHAR2,
  1024.                                     old_value IN DATE,
  1025.                                     new_value IN DATE);
  1026.   -- Update the old value with the new value.  The new value must be unique.  
  1027.   -- The change in value becomes effective immediately.  
  1028.   -- Note that implicit conversion will work from many different
  1029.   -- data types into VARCHAR2.
  1030.   -- Input Parameters:
  1031.   --    sname: The name of the schema containing the table to be replicated.  
  1032.   --           Defaults to invoking user. 
  1033.   --    pgroup: The name of the priority group.
  1034.   --    old_value: The old value to be altered.
  1035.   --    new_value: The new value. 
  1036.   -- Exceptions:
  1037.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1038.   --    duplicatevalue: if the given new value already exists in the priority 
  1039.   --           group.
  1040.   --    missingprioritygroup: if the given priority group does not exist.
  1041.   --    typefailure: if the given value has an incorrect datatype for the 
  1042.   --           priority group.
  1043.  
  1044.   PROCEDURE alter_priority(sname in VARCHAR2,
  1045.                            pgroup IN VARCHAR2,
  1046.                            old_priority IN NUMBER,
  1047.                            new_priority IN NUMBER);
  1048.   -- Update an old priority to a new priority.   The new priority must be unique.
  1049.   -- The change in priority becomes effective immediately.  
  1050.   --
  1051.   -- Input Parameters:
  1052.   --    sname: The name of the schema containing the table to be replicated.  
  1053.   --           Defaults to invoking user. 
  1054.   --    pgroup: The name of the priority group.
  1055.   --    old_priority: The priority to be altered.  
  1056.   --    new_priority:  The new priority.  
  1057.   -- Exceptions:
  1058.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1059.   --    duplicatepriority: if the given new priority already exists in the 
  1060.   --           priority group.
  1061.   --    missingprioritygroup: if the given priority group does not exist.
  1062.  
  1063.   PROCEDURE drop_priority(sname IN VARCHAR2,
  1064.                           pgroup IN VARCHAR2,
  1065.                           priority_num IN NUMBER);
  1066.   -- Remove a value from the given priority group by priority.  
  1067.   -- The removal of this value becomes effective immediately.  
  1068.   --
  1069.   -- Input Parameters:
  1070.   --    sname: The name of the schema containing the table to be replicated.  
  1071.   --           Defaults to invoking user.
  1072.   --    pgroup: The name of the priority group.
  1073.   --    priority: The priority for the value being dropped.  
  1074.   -- Exceptions:
  1075.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1076.   --    missingprioritygroup: if the given priority group does not exist.
  1077.  
  1078.   PROCEDURE drop_priority_number(sname in VARCHAR2,
  1079.                                pgroup IN VARCHAR2,
  1080.                                value IN NUMBER);
  1081.   PROCEDURE drop_priority_char(sname in VARCHAR2,
  1082.                                pgroup IN VARCHAR2,
  1083.                                value IN CHAR);
  1084.   PROCEDURE drop_priority_varchar2(sname in VARCHAR2,
  1085.                                pgroup IN VARCHAR2,
  1086.                                value IN VARCHAR2);
  1087.   PROCEDURE drop_priority_date(sname in VARCHAR2,
  1088.                                pgroup IN VARCHAR2,
  1089.                                value IN DATE);
  1090.   PROCEDURE drop_priority_raw (sname in VARCHAR2,
  1091.                                pgroup IN VARCHAR2,
  1092.                                value IN RAW);
  1093.   -- Remove a value from the given priority group.  
  1094.   -- The removal of this value becomes effective immediately.  
  1095.   -- Note that implicit conversion will work from many different
  1096.   -- data types into VARCHAR2.
  1097.   -- Input Parameters:
  1098.   --    sname: The name of the schema containing the table to be replicated.  
  1099.   --           Defaults to invoking user.
  1100.   --    pgroup: The name of the priority group.
  1101.   --    value: The value to be dropped
  1102.   -- Exceptions:
  1103.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1104.   --    missingprioritygroup: if the given priority group does not exist.
  1105.   --    typefailure: if the given value has an incorrect datatype for the 
  1106.   --           priority group.
  1107.  
  1108.   PROCEDURE define_site_priority(sname IN VARCHAR2,
  1109.                                  name IN VARCHAR2,
  1110.                                  comment IN VARCHAR2 := NULL);
  1111.   -- Create a new site priority.  The site priority name must be unique in a 
  1112.   -- repschema.  Define_site_priority does not affect the generated PL/SQL 
  1113.   -- until the next call to generate_replication_support.  
  1114.   -- Input Parameters:
  1115.   --    sname: The name of the schema containing the table to be replicated.  
  1116.   --           Defaults to invoking user. 
  1117.   --    name: The name of the site priority being created.
  1118.   --    comment: Comment text for the site priority being created.
  1119.   -- Exceptions:
  1120.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1121.   --    missingschema: if the given repschema does not exist.
  1122.   --    duplicatepriority: if the given site priority already exists in the 
  1123.   --           repschema.
  1124.  
  1125.   PROCEDURE comment_on_site_priority(sname IN VARCHAR2,
  1126.                                      name IN VARCHAR2,
  1127.                                      comment IN VARCHAR2);
  1128.   -- Update the comment field for the given site priority.
  1129.   -- Input Parameters:
  1130.   --    sname: The name of the schema containing the table to be replicated.  
  1131.   --           Defaults to invoking user. 
  1132.   --    name: The name of the site priority.
  1133.   --    comment: Comment text for the site priority being created.
  1134.   -- Exceptions:
  1135.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1136.   --    missingpriority: if the given site priority does not exist.
  1137.  
  1138.   PROCEDURE drop_site_priority(sname IN VARCHAR2,
  1139.                                name in VARCHAR2);
  1140.   -- Drop the given site priority.  Drop_site_priority does not affect the 
  1141.   -- generated PL/SQL until the next call to generate_replication_support.  
  1142.   -- Users cannot drop a site priority if the site priority is still referenced 
  1143.   -- in any generated resolution packages.
  1144.   -- Input Parameters:
  1145.   --    sname: The name of the schema containing the table to be replicated.  
  1146.   --           Defaults to invoking user. 
  1147.   --    name: The name of the site priority.
  1148.   -- Exceptions:
  1149.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1150.   --    referenced: if the given site priority is being used in conflict 
  1151.   --           resolution.
  1152.  
  1153.   PROCEDURE add_site_priority_site(sname in VARCHAR2,
  1154.                                    name IN VARCHAR2,
  1155.                                    site IN VARCHAR2,
  1156.                                    priority IN NUMBER);
  1157.   -- Add a new site to the given site priority.  The new site must be unique, 
  1158.   -- and the priority must be unique.  The addition of this site becomes 
  1159.   -- effective immediately.  
  1160.   -- Input Parameters:
  1161.   --    sname: The name of the schema containing the table to be replicated.
  1162.   --           Defaults to invoking user. 
  1163.   --    name: The name of the site priority.
  1164.   --    site: A new site for the site priority.  The site value should come 
  1165.   --          from global_name view.  It must already be canonicalized.
  1166.   --    priority: The priority for the new site.  
  1167.   -- Exceptions:
  1168.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1169.   --    duplicatesite: if the given site already exists in the site priority.
  1170.   --    duplicatepriority: if the given priority already exists in the site 
  1171.   --           priority.
  1172.   --    missingpriority if the given site priority does not exist.
  1173.  
  1174.   PROCEDURE alter_site_priority_site(sname in VARCHAR2,
  1175.                                      name IN VARCHAR2,
  1176.                                      old_site IN VARCHAR2,
  1177.                                      new_site IN VARCHAR2);
  1178.   -- Update the old site with the new site.  The new site must be unique.  
  1179.   -- The change in site becomes effective immediately.  
  1180.   -- Input Parameters:
  1181.   --    sname: The name of the schema containing the table to be replicated.  
  1182.   --           Defaults to invoking user. 
  1183.   --    name: The name of the site priority.
  1184.   --    old_site: The old site to be altered.
  1185.   --    old_site: The new site. 
  1186.   -- Exceptions:
  1187.   --    nonmasterdef if the invocation site is not the masterdef site.
  1188.   --    duplicatesite if the given new site already exists in the site priority.
  1189.   --    missingpriority if the given site priority does not exist.
  1190.  
  1191.   PROCEDURE alter_site_priority(sname in VARCHAR2,
  1192.                                 name IN VARCHAR2,
  1193.                                 old_priority IN NUMBER,
  1194.                                 new_priority IN NUMBER);
  1195.   -- Update an old priority to a new priority.   The new priority must be unique.
  1196.   -- The change in priority becomes effective immediately.  
  1197.   -- Input Parameters:
  1198.   --    sname: The name of the schema containing the table to be replicated.
  1199.   --           Defaults to invoking user.
  1200.   --    name: The name of the site priority.
  1201.   --    old_priority: The priority to be altered.
  1202.   --    new_priority: The new priority.
  1203.   -- Exceptions:
  1204.   --    nonmasterdef if the invocation site is not the masterdef site.
  1205.   --    duplicatesite if the given new site already exists in the site priority.
  1206.   --    missingpriority if the given site priority does not exist.
  1207.  
  1208.   PROCEDURE drop_site_priority_site(sname in VARCHAR2,
  1209.                                     name IN VARCHAR2,
  1210.                                     site IN VARCHAR2);
  1211.   -- Remove a site from the given site priority.  The removal of this site 
  1212.   -- becomes effective immediately.  
  1213.   -- Input Parameters:
  1214.   --    sname: The name of the schema containing the table to be replicated.  
  1215.   --           Defaults to invoking user. 
  1216.   --    name: The name of the site priority.
  1217.   --    site: The site to be dropped.
  1218.   -- Exceptions:
  1219.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1220.   --    missingpriority: if the given site priority does not exist.
  1221.  
  1222.   PROCEDURE add_update_resolution(sname                 IN VARCHAR2,
  1223.                                   oname                 IN VARCHAR2,
  1224.                                   column_group          IN VARCHAR2,
  1225.                                   sequence_no           IN NUMBER,
  1226.                                   method                IN VARCHAR2,
  1227.                                   parameter_column_name 
  1228.                                             IN dbms_repcat.varchar2s,
  1229.                                   priority_group IN VARCHAR2 := NULL,
  1230.                                   function_name  IN VARCHAR2 := NULL,
  1231.                                   comment        IN VARCHAR2 := NULL);
  1232.  
  1233.   PROCEDURE add_update_resolution(sname                 IN VARCHAR2,
  1234.                                   oname                 IN VARCHAR2,
  1235.                                   column_group          IN VARCHAR2,
  1236.                                   sequence_no           IN NUMBER,
  1237.                                   method                IN VARCHAR2,
  1238.                                   parameter_column_name IN VARCHAR2,
  1239.                                   priority_group IN VARCHAR2 := NULL,
  1240.                                   function_name  IN VARCHAR2 := NULL,
  1241.                                   comment        IN VARCHAR2 := NULL);
  1242.  
  1243.   PROCEDURE add_delete_resolution(sname          IN VARCHAR2,
  1244.                                   oname          IN VARCHAR2,
  1245.                                   sequence_no    IN NUMBER,
  1246.                                   parameter_column_name 
  1247.                                             IN dbms_repcat.varchar2s,
  1248.                                   function_name  IN VARCHAR2,
  1249.                                   comment        IN VARCHAR2 := NULL);
  1250.  
  1251.   PROCEDURE add_delete_resolution(sname          IN VARCHAR2,
  1252.                                   oname          IN VARCHAR2,
  1253.                                   sequence_no    IN NUMBER,
  1254.                                   parameter_column_name IN VARCHAR2,
  1255.                                   function_name  IN VARCHAR2,
  1256.                                   comment        IN VARCHAR2      := NULL);
  1257.  
  1258.  
  1259.   PROCEDURE add_unique_resolution(sname           IN VARCHAR2,
  1260.                                   oname           IN VARCHAR2,
  1261.                                   constraint_name IN VARCHAR2,
  1262.                                   sequence_no     IN NUMBER,
  1263.                                   method          IN VARCHAR2, 
  1264.                                   parameter_column_name 
  1265.                                             IN dbms_repcat.varchar2s,
  1266.                                   function_name   IN VARCHAR2 := NULL,
  1267.                                   comment         IN VARCHAR2 := NULL);
  1268.  
  1269.   PROCEDURE add_unique_resolution(sname           IN VARCHAR2,
  1270.                                   oname           IN VARCHAR2,
  1271.                                   constraint_name IN VARCHAR2,
  1272.                                   sequence_no     IN NUMBER,
  1273.                                   method          IN VARCHAR2,
  1274.                                   parameter_column_name IN VARCHAR2,
  1275.                                   function_name   IN VARCHAR2 := NULL,
  1276.                                   comment         IN VARCHAR2 := NULL);
  1277.  
  1278.   -- Add a new conflict resolution for the given object.  
  1279.   -- Add_update_resolution does not affect the generated PL/SQL until the 
  1280.   -- next call to generate_replication_support on the given object.   
  1281.   -- Input Parameters:
  1282.   --    sname: The name of the schema containing the table to be replicated.  
  1283.   --           Defaults to invoking user. 
  1284.   --    oname: The name of the table being replicated.
  1285.   --    column_group: name of the column_group
  1286.   --    sequence_no: A number which indicates the order conflict resolutions 
  1287.   --           are applied.  A smaller sequence number precedes a larger one.  
  1288.   --    method: The conflict resolution method. 
  1289.   --    parameter_column_name: An ordered list of columns to be used for 
  1290.   --           resolving the conflict.  May also be a comma-separated list.
  1291.   --            a '*' as the only entry in the list results in all the
  1292.   --            columns in the column group being entered in the alphebetical
  1293.   --            order (only applicable for 'user function'
  1294.   --    priority_group: If the method is `PRIORITY GROUP', enter the name of 
  1295.   --           priority group used for resolving the conflict.
  1296.   --    function_name: If the method is `USER FUNCTION', enter the user 
  1297.   --           resolution function name here.
  1298.   --    comment: Comment text for the conflict resolution being defined.
  1299.   -- Exceptions:
  1300.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1301.   --    missingobject: if the given object does not exist as a table in the 
  1302.   --           replicated schema awaiting replication information.
  1303.   --    duplicatesequence: if the sequence number already exists for the given 
  1304.   --           object.
  1305.   --    missingcolumn: if the given columns do not exist in the table.  
  1306.   --    missinggroup: if the given column group does not exist for the table.
  1307.   --    invalidmethod: if the given resolution method does not exist.
  1308.   --    invalidprioritygroup: if the given priority group does not exist.
  1309.   --    invalidparameter: if the given number of parameter columns is invalid.
  1310.   --    missingfunction: if the user function does not exist. 
  1311.  
  1312.   PROCEDURE comment_on_update_resolution(sname IN VARCHAR2,
  1313.                                          oname IN VARCHAR2,
  1314.                                          column_group IN VARCHAR2,
  1315.                                          sequence_no IN NUMBER,
  1316.                                          comment IN VARCHAR2);
  1317.   -- Update the comment field for the given update conflict resolution.   
  1318.   -- Input Parameters:
  1319.   --    sname: The name of the schema containing the table to be replicated.  
  1320.   --           Defaults to invoking user. 
  1321.   --    oname: The name of the table being replicated.
  1322.   --    column_group: The name of the column group
  1323.   --    sequence_no: A number which indicates the order conflict resolutions 
  1324.   --           are applied.  A smaller sequence number precedes a larger one.  
  1325.   --    comment: Comment text for the conflict resolution being defined.
  1326.   -- Exceptions:
  1327.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1328.   --    missingobject: if the given object does not exist as a table in the 
  1329.   --           replicated schema awaiting replication information.
  1330.   --    missingresolution: if the given conflict resolution does not exist.
  1331.  
  1332.   PROCEDURE comment_on_delete_resolution(sname IN VARCHAR2,
  1333.                                          oname IN VARCHAR2,
  1334.                                          sequence_no IN NUMBER,
  1335.                                          comment IN VARCHAR2) ;
  1336.   -- Update the comment field for the given delete conflict resolution.  
  1337.   -- Input Parameters:
  1338.   --    sname: The name of the schema containing the table to be replicated.  
  1339.   --           Defaults to invoking user. 
  1340.   --    oname: The name of the table being replicated.
  1341.   --    sequence_no: A number which indicates the order conflict resolutions 
  1342.   --           are applied.  A smaller sequence number precedes a larger one.  
  1343.   --    comment: Comment text for the conflict resolution being defined.
  1344.   -- Exceptions:
  1345.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1346.   --    missingobject: if the given object does not exist as a table in the 
  1347.   --           replicated schema awaiting replication information.
  1348.   --    missingresolution: if the given conflict resolution does not exist.
  1349.  
  1350.   PROCEDURE comment_on_unique_resolution(sname IN VARCHAR2,
  1351.                                          ONAME in VARCHAR2,
  1352.                                          constraint_name IN VARCHAR2,
  1353.                                          sequence_no IN NUMBER,
  1354.                                          comment IN VARCHAR2) ;
  1355.   -- Update the comment field for the given delete conflict resolution.
  1356.   -- Input Parameters:
  1357.   --    sname: The name of the schema containing the table to be replicated.  
  1358.   --           Defaults to invoking user. 
  1359.   --    oname: The name of the table being replicated.
  1360.   --    constraint_name: The name of the unique constraint to be resolved.  
  1361.   --    sequence_no: A number which indicates the order conflict resolutions are 
  1362.   --           applied.  A smaller sequence number precedes a larger one.  
  1363.   --    comment: Comment text for the conflict resolution being defined.
  1364.   --    Update: the comment field for the given uniqueness conflict resolution.  
  1365.   -- Exceptions:
  1366.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1367.   --    missingobject: if the given object does not exist as a table in the 
  1368.   --           replicated schema awaiting replication information.
  1369.   --    missingresolution: if the given conflict resolution does not exist.
  1370.  
  1371.   PROCEDURE drop_update_resolution(sname IN VARCHAR2,
  1372.                                    oname IN VARCHAR2,
  1373.                                    column_group IN VARCHAR2,
  1374.                                    sequence_no IN NUMBER) ;
  1375.  
  1376.   -- Remove an update conflict resolution for the given object.    
  1377.   -- Drop_update_resolution does not affect the generated PL/SQL until the 
  1378.   -- next call to generate_replication_support on the given object.   
  1379.   -- Input Parameters:
  1380.   --    sname: The name of the schema containing the table to be replicated.
  1381.   --           Defaults to invoking user.
  1382.   --    oname: The name of the table being replicated.
  1383.   --    column_group_name: enter column group name
  1384.   --    sequence_no: A number which indicates the order conflict resolutions 
  1385.   --           are applied.  A smaller sequence number precedes a larger one.  
  1386.   -- Exceptions:
  1387.   --    nonmasterdef: if the invocation site is not the masterdef site.
  1388.   --    missingobject: if the given object does not exist as a table in 
  1389.   --           the replicated schema awaiting replication information.
  1390.  
  1391.   PROCEDURE drop_delete_resolution(sname IN VARCHAR2,
  1392.                                    oname IN VARCHAR2,
  1393.                                    sequence_no IN NUMBER) ;
  1394.   -- Remove a delete conflict resolution for the given object.  
  1395.   -- Drop_delete_resolution does not affect the generated PL/SQL until 
  1396.   -- the next call to generate_replication_support on the given object.   
  1397.   -- Input Parameters:
  1398.   --     sname: The name of the schema containing the table to be replicated.  
  1399.   --            Defaults to invoking user. 
  1400.   --     oname: The name of the table being replicated.
  1401.   --     sequence_no: A number which indicates the order conflict resolutions 
  1402.   --            are applied.  A smaller sequence number precedes a larger one.  
  1403.   -- Exceptions:
  1404.   --     nonmasterdef: if the invocation site is not the masterdef site.
  1405.   --     missingobject: if the given object does not exist as a table in 
  1406.   --            the replicated schema awaiting replication information.
  1407.  
  1408.   PROCEDURE drop_unique_resolution(sname IN VARCHAR2,
  1409.                                    oname IN VARCHAR2,
  1410.                                    constraint_name IN VARCHAR2,
  1411.                                    sequence_no IN NUMBER) ;
  1412.   -- Remove a uniqueness conflict resolution for the given object.    
  1413.   -- Drop_unique_resolution does not affect the generated PL/SQL 
  1414.   -- until the next call to generate_replication_support on the given object.   
  1415.   -- Input Parameters:
  1416.   --     sname: The name of the schema containing the table to be replicated.  
  1417.   --            Defaults to invoking user.
  1418.   --     oname: The name of the table being replicated.
  1419.   --     constraint_name: The name of the unique constraint to be resolved.  
  1420.   --     sequence_no: A number which indicates the order conflict resolutions 
  1421.   --            are applied.  A smaller sequence number precedes a larger one.
  1422.   -- Exceptions:
  1423.   --     nonmasterdef: if the invocation site is not the masterdef site.
  1424.   --     missingobject: if the given object does not exist as a table in 
  1425.   --            the replicated schema awaiting replication information.
  1426.  
  1427.   PROCEDURE purge_statistics(sname      IN VARCHAR2,
  1428.                              oname      IN VARCHAR2,
  1429.                              start_date IN DATE,
  1430.                              end_date   IN DATE);
  1431.   -- Purge the collected statistics for the given range of date in which
  1432.   -- conflicts were resolved. 
  1433.   -- Input Parameters:
  1434.   --    sname: The name of the schema containing the table to be replicated.
  1435.   --    oname: The name of the table being replicated.
  1436.   --    start_date: The start date of the given range.  If NULL, assume no
  1437.   --                start date.
  1438.   --    end_date: The end date of the given range.  If NULL, assume no end date.
  1439.  
  1440.   PROCEDURE register_statistics(sname IN VARCHAR2,
  1441.                                 oname IN VARCHAR2);
  1442.   -- Enable the collection of conflict resolution statistics for the given
  1443.   -- replicated table.
  1444.   -- Input Parameters:
  1445.   --    sname: The name of the schema containing the table to be replicated.
  1446.   --    oname: The name of the table being replicated.
  1447.  
  1448.   PROCEDURE cancel_statistics(sname IN VARCHAR2,
  1449.                               oname IN VARCHAR2);
  1450.   -- Cancel the collection of conflict resolution statistics for the given
  1451.   -- replicated table. 
  1452.   -- Input Parameters:
  1453.   --    sname: The name of the schema containing the table to be replicated.
  1454.   --    oname: The name of the table being replicated.
  1455.  
  1456. END dbms_repcat;
  1457. /
  1458.  
  1459. DROP PUBLIC SYNONYM dbms_repcat;
  1460.  
  1461. CREATE PUBLIC SYNONYM dbms_repcat for dbms_repcat;
  1462.  
  1463.  
  1464. CREATE OR REPLACE PACKAGE dbms_repcat_auth AS
  1465.  
  1466.   -- This package is separate from the other repcat packages to avoid
  1467.   -- deadlocks.
  1468.  
  1469.   PROCEDURE grant_surrogate_repcat(userid IN VARCHAR2);
  1470.   -- This procedure grants enough privileges and roles to the specified
  1471.   -- user and creates enough synonyms to let that user operate on behalf
  1472.   -- of repcat at this instance.  This avoids the need for a clique of
  1473.   -- SYS/SYS_PASSWORD dblinks.  These privileges and roles should not
  1474.   -- be granted to replication users.
  1475.   --
  1476.   -- Exceptions:
  1477.   --   ORA-01917 if the user does not exist.
  1478.  
  1479.   PROCEDURE revoke_surrogate_repcat(userid IN VARCHAR2);
  1480.   -- This procedure revokes all privileges and roles that would be
  1481.   -- granted to the specified user with grant_surrogate_repcat.
  1482.   -- It also drops any synonyms that would have been created.
  1483.   -- WARNING: identical privileges and roles that were granted
  1484.   -- independently of grant_surrogate_repcat will also be revoked.
  1485.   -- Identically named synonyms that were created independently of
  1486.   -- grant_surrogate_repcat will also be dropped.
  1487.   --
  1488.   -- Exceptions:
  1489.   --   ORA-01917 if the user does not exist.
  1490.  
  1491. END dbms_repcat_auth;
  1492. /
  1493.  
  1494.  
  1495. CREATE OR REPLACE PACKAGE dbms_repcat_admin AS
  1496.  
  1497.   -------------------------
  1498.   -- OVERVIEW
  1499.   --
  1500.  
  1501.   -- This package exports procedures that grant or revoke a set of
  1502.   -- privileges useful for administering replication on one or more
  1503.   -- local schemas.  The package body is included in this file to make
  1504.   -- the privileges apparent as well as to provide an example for
  1505.   -- sophisticated customers that want to implement similar functionality.
  1506.   --
  1507.   -- The following procedures can be customized by doing explicit
  1508.   -- GRANTS and REVOKES after the procedure is invoked if the canned
  1509.   -- privileges are insufficient or too powerful.  Any modification
  1510.   -- to these procedures will not be supported.
  1511.  
  1512.   -----------
  1513.   -- SECURITY
  1514.   -- 
  1515.  
  1516.   -- Because this package grants and revokes many powerful privileges,
  1517.   -- execute privileges on the package should not be granted widely.
  1518.  
  1519.   -------------
  1520.   -- PROCEDURES
  1521.   --
  1522.  
  1523.   PROCEDURE grant_admin_repschema(userid IN VARCHAR2);
  1524.   -- Grant enough privileges and roles to the specified user so that user
  1525.   -- can do typical repcat administration of a replicated schema of the same
  1526.   -- name at this instance.  This procedure is appropriate when the instance
  1527.   -- is, or will be, a master site or a snapshot site for the replicated
  1528.   -- schema.
  1529.   --
  1530.   -- Exceptions:
  1531.   --   ORA-01917 if the user does not exist.
  1532.  
  1533.   PROCEDURE revoke_admin_repschema(userid IN VARCHAR2);
  1534.   -- If userid is SYS, this procedure has no effect.  Otherwise,
  1535.   -- this procedure revokes all privileges and roles that would be
  1536.   -- granted to the specified user with grant_admin_repschema.
  1537.   -- WARNING: identical privileges and roles that were granted
  1538.   -- independently of grant_admin_repschema will also be revoked.
  1539.   --
  1540.   -- Exceptions:
  1541.   --   ORA-01917 if the user does not exist.
  1542.  
  1543.   PROCEDURE grant_admin_any_repschema(userid IN VARCHAR2);
  1544.   -- Grant enough privileges and roles to the specified user so that user
  1545.   -- can do typical repcat administration of any replicated schema at this
  1546.   -- instance.  This procedure is appropriate when the instance is, or
  1547.   -- will be, a master site and/or a snapshot site for replicated schemas.
  1548.   --
  1549.   -- Exceptions:
  1550.   --   ORA-01917 if the user does not exist.
  1551.  
  1552.   PROCEDURE revoke_admin_any_repschema(userid IN VARCHAR2);
  1553.   -- If userid is SYS, this procedure has no effect.  Otherwise,
  1554.   -- this procedure revokes all privileges and roles that would be
  1555.   -- granted to the specified user with grant_admin_any_repschema.
  1556.   -- WARNING: identical privileges and roles that were granted
  1557.   -- independently of grant_admin_any_repschema will also be revoked.
  1558.   --
  1559.   -- Exceptions:
  1560.   --   ORA-01917 if the user does not exist.
  1561.  
  1562. END dbms_repcat_admin;
  1563. /
  1564.  
  1565.  
  1566. CREATE OR REPLACE PACKAGE BODY dbms_repcat_admin AS
  1567.  
  1568.  
  1569.   PROCEDURE do_sql(statement IN VARCHAR2,
  1570.                    resignal  IN BOOLEAN) IS
  1571.   -- Use dbms_sql to execute the parameter statement.
  1572.   -- Raise any exception if resignal is TRUE.
  1573.  
  1574.   sql_cursor NUMBER;
  1575.   dummy      NUMBER;
  1576.  
  1577.   BEGIN
  1578.     sql_cursor := dbms_sql.open_cursor;
  1579.     dbms_sql.parse(sql_cursor, statement, dbms_sql.v7);
  1580.     dummy := dbms_sql.execute(sql_cursor);
  1581.     dbms_sql.close_cursor(sql_cursor);
  1582.   EXCEPTION WHEN others THEN
  1583.     IF dbms_sql.is_open(sql_cursor) THEN
  1584.       dbms_sql.close_cursor(sql_cursor);
  1585.     END IF;
  1586.     IF resignal THEN RAISE;
  1587.     END IF;
  1588.   END do_sql;
  1589.  
  1590.  
  1591.   FUNCTION get_nls_substr(s      IN     VARCHAR2,
  1592.                           offset IN OUT NUMBER,
  1593.                           len    IN     NUMBER) RETURN VARCHAR2 IS
  1594.   -- Return the largest substring of s that begins at character offset offset,
  1595.   -- fits in len bytes, and does not split any characters.  The OUT value of
  1596.   -- offset points to the first character after the returned substring if it
  1597.   -- exists.  Otherwise, offset is larger than the length of s in characters.
  1598.  
  1599.   max_bytes_per_char CONSTANT NUMBER := 4;
  1600.   char_count                  INTEGER := len;
  1601.   excess                      NUMBER;
  1602.  
  1603.   BEGIN
  1604.     WHILE char_count > 0 LOOP
  1605.       excess := LENGTHB(SUBSTR(s, offset, char_count)) - len;
  1606.       IF excess <= 0 THEN EXIT;
  1607.       END IF;
  1608.       excess := excess/max_bytes_per_char;
  1609.       IF excess < 1 THEN excess := 1;        -- prevent looping
  1610.       END IF;
  1611.       char_count := char_count - excess;
  1612.     END LOOP;
  1613.   offset := offset + char_count;
  1614.   RETURN SUBSTR(s, offset-char_count, char_count);
  1615.   END get_nls_substr;
  1616.  
  1617.  
  1618.   PROCEDURE canonicalize(name       IN  VARCHAR2,
  1619.                          canon_name OUT VARCHAR2,
  1620.                          canon_len  IN  NUMBER) IS
  1621.   -- Canonicalize the string passed in as parameter name, determine the
  1622.   -- longest prefix that fits in canon_len bytes, and return the result in 
  1623.   -- canon_name.  Canonicalization is defined as follows.  If name is NULL,
  1624.   -- canon_name becomes NULL.  If name begins and ends with a double quote,
  1625.   -- remove both.  Otherwise, convert name to upper case with NLS_UPPER.
  1626.  
  1627.   name_length NUMBER;
  1628.   dummy       NUMBER := 1;
  1629.  
  1630.   BEGIN
  1631.     IF name is NULL THEN
  1632.       canon_name := NULL;
  1633.       RETURN;
  1634.     END IF;
  1635.     name_length := LENGTH(name);
  1636.     IF SUBSTR(name, 1, 1) = '"' AND SUBSTR(name, name_length, 1) = '"' THEN
  1637.       canon_name := get_nls_substr(SUBSTR(name, 2, name_length-2), dummy,
  1638.                                    canon_len);
  1639.     ELSE canon_name := get_nls_substr(NLS_UPPER(name), dummy, canon_len);
  1640.     END IF;
  1641.   END canonicalize;
  1642.  
  1643.  
  1644.   FUNCTION ensure_user_exists(userid IN VARCHAR2) RETURN VARCHAR2 IS
  1645.   -- Canonicalize userid.  If the user does not exist, raise ORA-01917.
  1646.   -- Otherwise, return the canonicalized form of userid.
  1647.  
  1648.   canon_user VARCHAR2(30);
  1649.   user_count NUMBER;
  1650.  
  1651.   BEGIN
  1652.     canonicalize(userid, canon_user, 30);
  1653.     SELECT COUNT(*) INTO user_count
  1654.       FROM DBA_USERS
  1655.       WHERE username = canon_user;
  1656.     IF user_count = 0 THEN
  1657.       -- raise an exception unless user created in the interim
  1658.       do_sql('GRANT CREATE SYNONYM TO "' || canon_user || '"', TRUE);
  1659.     END IF;
  1660.     RETURN canon_user;
  1661.   END ensure_user_exists;
  1662.  
  1663.  
  1664.   PROCEDURE grant_admin(userid   IN VARCHAR2,
  1665.                         multiple IN BOOLEAN,
  1666.                         grants   IN BOOLEAN) IS
  1667.   -- Grant/revoke the privileges and roles required to do typical repcat
  1668.   -- administration on one or all local repschemas.  The target is
  1669.   -- the user identified by userid.
  1670.   -- If multiple is TRUE, the privileges apply to any local repschema.
  1671.   -- Otherwise, the privileges apply to only the local repschema given
  1672.   -- by userid.
  1673.   -- If grants is TRUE, grant these privileges and roles.
  1674.   -- If grants is FALSE and the user is not SYS, revoke these privileges and
  1675.   -- roles.
  1676.   -- If grants is FALSE and the user is SYS, do nothing.
  1677.  
  1678.   canon_user VARCHAR2(38);
  1679.   verb       VARCHAR2(7);
  1680.   any_null   VARCHAR2(4);
  1681.   is_sys     BOOLEAN;
  1682.  
  1683.   BEGIN
  1684.     canon_user := ensure_user_exists(userid);
  1685.     is_sys := canon_user = 'SYS';
  1686.  
  1687.     -- avoid deadlocks and mistakes
  1688.     IF is_sys AND NOT grants THEN RETURN;
  1689.     END IF;
  1690.  
  1691.     IF multiple THEN
  1692.       any_null := 'ANY ';
  1693.     ELSE any_null := '';
  1694.     END IF;
  1695.     IF grants THEN
  1696.       verb := 'GRANT ';
  1697.       canon_user := ' TO "' || canon_user || '"';
  1698.     ELSE
  1699.       verb := 'REVOKE ';
  1700.       canon_user := ' FROM "' || canon_user || '"';
  1701.     END IF;
  1702.     do_sql(verb || 'CREATE SESSION' || canon_user, grants);
  1703.     do_sql(verb || 'ALTER SESSION' || canon_user, grants);
  1704.     IF NOT is_sys THEN
  1705.       do_sql(verb || 'EXECUTE ON SYS.DBMS_DEFER' || canon_user, grants);
  1706.       do_sql(verb || 'EXECUTE ON SYS.DBMS_DEFER_SYS' || canon_user, grants);
  1707.       do_sql(verb || 'EXECUTE ON SYS.DBMS_REPCAT' || canon_user, grants);
  1708.       do_sql(verb || 'EXECUTE ON SYS.DBMSOBJGWRAPPER' || canon_user, grants);
  1709.     END IF;
  1710.     do_sql(verb || 'UNLIMITED TABLESPACE' || canon_user, grants);
  1711.  
  1712.     IF multiple THEN
  1713.       do_sql(verb || 'DBA' || canon_user, grants);
  1714.       do_sql(verb || 'SELECT ANY TABLE' || canon_user, grants);
  1715.       do_sql(verb || 'INSERT ANY TABLE' || canon_user, grants);
  1716.       do_sql(verb || 'DELETE ANY TABLE' || canon_user, grants);
  1717.     END IF;
  1718.  
  1719.     do_sql(verb || 'CREATE ' || any_null || 'CLUSTER' || canon_user, grants);
  1720.     do_sql(verb || 'CREATE DATABASE LINK' || canon_user, grants);
  1721.     IF multiple THEN
  1722.       do_sql(verb || 'CREATE ANY INDEX' || canon_user, grants);
  1723.     END IF;
  1724.     do_sql(verb || 'CREATE ' || any_null || 'PROCEDURE' || canon_user, grants);
  1725.     do_sql(verb || 'CREATE ' || any_null || 'SEQUENCE' || canon_user, grants);
  1726.     do_sql(verb || 'CREATE ' || any_null || 'SNAPSHOT' || canon_user, grants);
  1727.     do_sql(verb || 'CREATE ' || any_null || 'SYNONYM' || canon_user, grants);
  1728.     do_sql(verb || 'CREATE ' || any_null || 'TABLE' || canon_user, grants);
  1729.     do_sql(verb || 'CREATE ' || any_null || 'TRIGGER' || canon_user, grants);
  1730.     do_sql(verb || 'CREATE ' || any_null || 'VIEW' || canon_user, grants);
  1731.  
  1732.     IF multiple THEN
  1733.       do_sql(verb || 'DROP ANY CLUSTER' || canon_user, grants);
  1734.       do_sql(verb || 'DROP ANY INDEX' || canon_user, grants);
  1735.       do_sql(verb || 'DROP ANY PROCEDURE' || canon_user, grants);
  1736.       do_sql(verb || 'DROP ANY SEQUENCE' || canon_user, grants);
  1737.       do_sql(verb || 'DROP ANY SYNONYM' || canon_user, grants);
  1738.       do_sql(verb || 'DROP ANY SNAPSHOT' || canon_user, grants);
  1739.       do_sql(verb || 'DROP ANY TABLE' || canon_user, grants);
  1740.       do_sql(verb || 'DROP ANY TRIGGER' || canon_user, grants);
  1741.       do_sql(verb || 'DROP ANY VIEW' || canon_user, grants);
  1742.     END IF;
  1743.  
  1744.     IF multiple THEN
  1745.       do_sql(verb || 'ALTER ANY CLUSTER' || canon_user, grants);
  1746.       do_sql(verb || 'ALTER ANY INDEX' || canon_user, grants);
  1747.       do_sql(verb || 'ALTER ANY PROCEDURE' || canon_user, grants);
  1748.       do_sql(verb || 'ALTER ANY SEQUENCE' || canon_user, grants);
  1749.       do_sql(verb || 'ALTER ANY SNAPSHOT' || canon_user, grants);
  1750.       do_sql(verb || 'ALTER ANY TABLE' || canon_user, grants);
  1751.       do_sql(verb || 'ALTER ANY TRIGGER' || canon_user, grants);
  1752.     END IF;
  1753.  
  1754.   END grant_admin;
  1755.  
  1756.  
  1757.   --------
  1758.   -- PACKAGE EXTERNAL PROCEDURES
  1759.   --
  1760.  
  1761.   PROCEDURE grant_admin_repschema(userid IN VARCHAR2) IS
  1762.   BEGIN
  1763.     grant_admin(userid, FALSE, TRUE);
  1764.   END grant_admin_repschema;
  1765.  
  1766.  
  1767.   PROCEDURE revoke_admin_repschema(userid IN VARCHAR2) IS
  1768.   BEGIN
  1769.     grant_admin(userid, FALSE, FALSE);
  1770.   END revoke_admin_repschema;
  1771.  
  1772.  
  1773.   PROCEDURE grant_admin_any_repschema(userid IN VARCHAR2) IS
  1774.   BEGIN
  1775.     grant_admin(userid, TRUE, TRUE);
  1776.   END grant_admin_any_repschema;
  1777.  
  1778.  
  1779.   PROCEDURE revoke_admin_any_repschema(userid IN VARCHAR2) IS
  1780.   BEGIN
  1781.     grant_admin(userid, TRUE, FALSE);
  1782.   END revoke_admin_any_repschema;
  1783.  
  1784. END dbms_repcat_admin;
  1785. /
  1786.