Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
DB Access Module for Oracle OCI User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

2.9 Stored Procedures

The DB Access Module for Oracle OCI includes support for RWDBStoredProc that is analogous to PL/SQL procedures and functions. (See the Oracle PL/SQL Language Reference.) OCI call OCIDescribeAny() is used to get parameter information for procedures and functions. SQL statements are made to create procedures and functions, to get their text, and to execute them.

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 using class RWDBStoredProc and the return value can be obtained using RWDBStoredProc::returnValue().


It is currently not possible to use RWDBStoredProc to encapsulate a PL/SQL procedure or function that has parameters of the Oracle datatypes CLOB and BLOB.

2.9.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 SourcePro C++ API Reference Guide 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.9.2 Input/Output Parameters and Result Sets

Input and output parameters can be passed to stored procedures. The DB Interface Module uses RWDBColumn to describe a parameter to a stored procedure.

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

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

The DB Interface Module 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 following sample stored procedure, written in PL/SQL, myCursor is a cursor variable.

The DB Interface Module enables your application to receive an RWDBResult containing the result sets returned by the reference cursors from the execution of a stored procedure. Notice in the following code fragment that the user does not explicitly shift a cursor parameter into the procedure:

2.9.3 Instantiating an RWDBStoredProc Using Schema Data

The member functions:

increase the performance of stored procedures by accepting a stored procedure schema from the user while constructing RWDBStoredProc objects. This eliminates the usual parameter fetch required for instantiations. The schema to be supplied to these methods 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, if set, is used first to avoid type mapping. The column should be supplied for any return value and must include a name and the datatype.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.