Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

2.8 Stored Procedures

The Oracle access library includes support for RWDBStoredProc that is analogous to PL/SQL procedures and functions. (See the Oracle PL/SQL User's Guide and Reference, Chapter 6.) Procedures and functions are implemented using the OCI call odessp() to get parameter information. SQL statements are made to create procedures and functions, to get their text, and to execute them.

Please note that PL/SQL differentiates between stored functions and procedures. PL/SQL functions cannot be created with the createProcedure() method of RWDBDatabase that we describe in the next section. Instead, you must use the executeSql() method of RWDBConnection. PL/SQL functions can be executed and the return value can be obtained using the RWDBStoredProc::returnValue() call.

2.8.1 Creating a Stored Procedure

A stored procedure is created using the CREATE OR REPLACE PROCEDURE... SQL statement. You can create the procedure by using the RWDBDatabase::createProcedure() call. In this case, the parameter list and body of the stored procedure must be supplied. The body should contain the following:

The following simple procedure to debit an account provides an example. The procedure takes two input parameters and one output parameter. The input parameters are the amount and the acct_id, and the output parameter is the new balance, new_bal.

After a stored procedure is created, it can be executed by instantiating an RWDBStoredProc and calling the execute() method. See the DBTools.h++ User's Guide and Reference for more information. It is the responsibility of the programmer to make sure that his or her stored procedure can be compiled by the PL/SQL compiler.

2.8.2 Input/Output Parameters and Result Sets

Input and output parameters can be passed to stored procedures. DBTools.h++ uses RWDBColumn to describe a parameter to a stored procedure.

The RWDBStoredProcedure::fetchReturnParams() must be used to load the output parameters.

There is no limit on the number of input/output parameters that can be exchanged between an RWDBStoredProc and a PL/SQL procedure. There is, however, a default value of 32 parameters.

To specify the number of parameters, for example, 40, you would proceed as follows:

DBTools.h++ provides support for stored procedures that contain cursor variables. A cursor variable is a reference to a cursor that is defined and opened on an Oracle server. In the sample stored procedure below, written in PL/SQL, myCursor is a cursor variable.

DBTools.h++ enables your application to receive an RWDBResult containing the result sets returned from the execution of a stored procedure, as in the following code fragment:

2.8.3 Instantiating an RWDBStoredProcedure Using Schema Data

The member function:

increases the performance of stored procedures by eliminating the usual parameter fetch required for instantiations. The schema can come from previously cached procedure schema, through RWDBStoredProc::params(), or from user-created schema. The user-created schema must include the name and the type of each parameter in the stored procedure. When the type is unknown, the native type should be used. The native type is used first to avoid type mapping, unless the native type is set to the default -1.

Here is an example that uses the procedure created in Section 2.8.2:


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.