−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 1. Specify the nodes to which the deferred RPC call is to be queued. −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− vNodes(1) := 'D7NY.BIGWHEEL.COM'; vNodes(2) := 'D7OH.BIGWHEEL.COM'; vNodes(3) := 'D7OR.BIGWHEEL.COM'; vNodes(4) := 'D7WA.BIGWHEEL.COM'; vNodes(5) := 'D7TX.BIGWHEEL.COM'; −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 2. Execute DBMS_DEFER.CALL, supplying the schema name, package name, −− procedure name, number of arguments to the procedure, and (if you do −− not use DBMS_CALL.TRANSACTION) the nodes parameter. −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− DBMS_DEFER.CALL(schema_name => 'SPROCKET', package_name => 'PRODUCTMAINT', proc_name => 'AddProduct', arg_count => 6, nodes => vNodes ); −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 3. Call DBMS_DEFER.<datatype>_arg arg_count times, where arg_count is −− the value passed to DBMS_DEFER.CALL. The order in which you call −− DBMS_DEFER.<datatype>_arg must be the same order as the parameters −− are listed in the procedure definition. −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− DBMS_DEFER.NUMBER_ARG( 10 ); −− product_type DBMS_DEFER.VARCHAR2_ARG( 'BIKE−0018' ); −− catalog_id DBMS_DEFER.VARCHAR2_ARG( 'Mens 18 Speed Racer'); −− Description DBMS_DEFER.VARCHAR2_ARG( '19971031−01' ); −− Rev Level DBMS_DEFER.DATE_ARG(to_date('31−OCT−1997','DD−MON−YYYY')); −−Date DBMS_DEFER.VARCHAR2_ARG( 'PLANNED' ); −− status −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −− 4. Call DBMS_DEFER.COMMIT_WORK with an optional comment. −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− DBMS_DEFER.COMMIT_WORK(commit_work_comment=>'5 Nodes, 6 args'); END; Let's see what happens when we execute AddProduct: SQL> execute qAddProduct PL/SQL procedure successfully completed. Note that even though this deferred RPC call is destined for five different databases, there is only one entry in DEFCALL: SQL> SELECT callno, 2 deferred_tran_db, 3 deferred_tran_id, 4 schemaname, 5 packagename, 6 procname, 7 argcount 8 FROM defcall 9 / Deferred Deferred Tran Tran Schema Package Procedure Arg Call No DB ID Name Name Name Count −−−−−−−−−−−− −−−−−−−−−−−−−−−−−− −−−−−−−−−−−−−−−−−−−−− −−−−−−−−−−− −−−−−−−−−−−−− 6631429922096 D7CA.BIGWHEEL.COM 2.125.13 SPROCKET PRODUCTMAINTAddProduct6 [Appendix A] What's on the Companion Disk? 17.3.3 Parameterized RPCs 796 The DEFTRANDEST data dictionary view, on the other hand, includes all of the destinations for this call: SQL> SELECT deferred_tran_id, 2 deferred_tran_db, 3 dblink 4 FROM deftrandest 5 / Deferred Deferred Tran Tran ID DB DB Link −−−−−−−− −−−−−−−−−−−−−−−−−−− −−−−−−−−−−−−−−−−−−−− 2.125.13 D7CA.BIGWHEEL.COM D7NY.BIGWHEEL.COM 2.125.13 D7CA.BIGWHEEL.COM D7OH.BIGWHEEL.COM 2.125.13 D7CA.BIGWHEEL.COM D7OR.BIGWHEEL.COM 2.125.13 D7CA.BIGWHEEL.COM D7WA.BIGWHEEL.COM 2.125.13 D7CA.BIGWHEEL.COM D7TX.BIGWHEEL.COM 5 rows selected. 17.2 DBMS_DEFER_SYS: Managing Deferred Transactions 17.4 DBMS_DEFER_QUERY: Performing Diagnostics and Maintenance Copyright (c) 2000 O'Reilly & Associates. All rights reserved. [Appendix A] What's on the Companion Disk? 17.3.3 Parameterized RPCs 797 Chapter 17 Deferred Transactions and Remote Procedure Calls 17.4 DBMS_DEFER_QUERY: Performing Diagnostics and Maintenance Occasionally, you may want to see details about deferred RPCs in the queue, such as what procedure and parameters are used. The DBMS_DEFER_QUERY package contains procedures to display this data. 17.4.1 Getting Started with DBMS_DEFER_QUERY The DBMS_REPCAT_QUERY package is created when the Oracle database is installed. The dbmsdefr.sql script (found in the built−in packages source directory, as described in Chapter 1) contains the source code for this package's specification. This script is called by catrep.sql, which must be run to install the advanced replication packages. The wrapped sql script prvtrctf.sql creates the public synonym DBMS_REPCAT_QUERY. No EXECUTE privileges are granted on DBMS_REPCAT_QUERY; only the owner (SYS) and those with the EXECUTE ANY PROCEDURE system privilege may execute the package. 17.4.1.1 DBMS_DEFER_QUERY programs Table 17.14 lists the programs available in the DBMS_DEFER_QUERY package. Table 17.14: DBMS_DEFER_QUERY Programs Name Description Use in SQL? GET_ARG_TYPE Returns the type of a parameter in a deferred call No GET_CALL_ARGS Returns information about parameters in text form No GET_<datatype>_ARG Returns the value of a parameter whose type is <datatype>; values can be CHAR, DATE, NUMBER, RAW, ROWID, or VARCHAR2 No There are no exceptions defined for this package. 17.4.1.2 DBMS_DEFER_QUERY nonprogram elements Table 17.15 lists the nonprogram elements defined for the DBMS_DEFER_QUERY package. Table 17.15: DBMS_DEFER_QUERY Other Elements 798 Name/Type Description TYPE type_ary Table of NUMBER TYPE val_ary Table of VARCHAR2(2000) The PL/SQL tables type_ary and val_ary are both used in parameters to the procedure GET_CALL_ARGS; type_ary is an output array for RPC parameter datatypes and val_ary is an output array of the parameter values. Table 17.16 shows the mapping of numbers to datatypes in type_ary. Table 17.16: Mapping Numbers to Datatypes Datatype Numeric Value in type_ary BFILE (Oracle8 only) 114 BLOB (Oracle8 only) 113 CFIL (Oracle8 only) 115 CHAR 96 CFIL (Oracle8 only) 112 DATE 12 NUMBER 2 RAW 23 ROWID 11 VARCHAR2 1 Before examining the details of the individual procedures, let's look at a basic example of how they are used. Suppose that we have queued a call to the ProductMaint.AddProduct procedure, as described in an earlier example. SQL> EXECUTE qAddProduct PL/SQL procedure successfully completed. We now have an entry in the DEFCALL data dictionary view: 1 SELECT callno, 2 deferred_tran_db, 3 deferred_tran_id, 4 schemaname, 5 packagename, 6 procname, 7 argcount 8* FROM defcall SYSTEM@D7CA SQL> / Deferred Deferred Tran Tran Schema Package Procedure Arg Call No DB ID Name Name Name Count −−−−−−−−−−−− −−−−−−−−−−−−−−−−− −−−−−−−−−−−− −−−−−−−−− −−−−−−−−−−− −−−−−−−−−−−−−−− 9929966326029D7CA.BIGWHEEL.COM 3.58.14 SPROCKET PRODUCTMAINTAddProduct6 1 row selected. [Appendix A] What's on the Companion Disk? 799 Here we see that the procedure ProductMaint.AddProduct is queued, and that it has six parameters. To determine what these parameters are, first determine their data types with the GET_ARG_TYPE procedure, and then determine their values with GET_<datatype>_ARG. Alternatively, you can use GET_CALL_ARGS, which returns all the information in a single call. The examples in the following sections illustrate the use of each technique. 17.4.1.3 The DBMS_DEFER_QUERY.GET_ARG_TYPE function You can use this function in conjunction with the GET_<datatype>_ARG or GET_CALL_ARGS functions to determine information about the deferred RPCs in the queue. GET_ARG_TYPE returns a number corresponding to the argument's datatype. Here is the specification for GET_ARG_TYPE: FUNCTION DBMS_DEFER_QUEUE.GET_ARG_TYPE (callno IN NUMBER, deferred_tran_db IN VARCHAR2, arg_no IN NUMBER, deferred_tran_id IN VARCHAR2) RETURN NUMBER; The following table shows the mapping of datatypes to return values. Argument Datatype GET_ARG_TYPE Return Code BFIL (Oracle8 only) 114 BLOB (Oracle8 only) 113 CFIL (Oracle8 only) 115 CHAR 96 CFIL (Oracle8 only) 112 DATE 12 NUMBER 2 RAW 23 ROWID 11 VARCHAR2 1 Notice that the datatypes here are limited to the Oracle−supplied datatypes; you cannot, for example, defer a call to a procedure that accepts a PL/SQL table as a parameter. Parameters are summarized in the following table. Name Description callno The CALLNO of the RPC, as stored in the DEFCALL data dictionary view deferred_tran_db Global name of the database deferring the call (also stored in DEFCALL) arg_no The position of the argument in the RPC deferred_tran_id The deferred_tran_id for the call (also stored in DEFCALL) There are no restrictions on calling GET_ARG_TYPE. [Appendix A] What's on the Companion Disk? 17.4.1 Getting Started with DBMS_DEFER_QUERY 800 . to Datatypes Datatype Numeric Value in type_ary BFILE (Oracle8 only) 114 BLOB (Oracle8 only) 113 CFIL (Oracle8 only) 115 CHAR 96 CFIL (Oracle8 only) 112 DATE 12 NUMBER 2 RAW 23 ROWID 11 VARCHAR2. values. Argument Datatype GET_ARG_TYPE Return Code BFIL (Oracle8 only) 114 BLOB (Oracle8 only) 113 CFIL (Oracle8 only) 115 CHAR 96 CFIL (Oracle8 only) 112 DATE 12 NUMBER 2 RAW 23 ROWID 11 VARCHAR2. DBMS_DEFER_QUERY The DBMS_REPCAT_QUERY package is created when the Oracle database is installed. The dbmsdefr.sql script (found in the built−in packages source directory, as described in Chapter 1)