Using Oracle stored procedures with result sets

Overview of basic steps

The following procedure assumes you are creating the stored procedure in the ISQL view of the Database painter in DataWindow Designer.

StepsTo use an Oracle stored procedure with a result set:

  1. Set up the ISQL view of the Database painter to create the stored procedure.

  2. Create the stored procedure with a result set as an IN OUT (reference) parameter.

  3. Create DataWindow objects that use the stored procedure as a data source.

Setting up the Database painter

When you create a stored procedure in the ISQL view of the Database painter, you must change the default SQL statement terminator character to one that you do not plan to use in your stored procedure syntax.

The default SQL terminator character for the Database painter is a semicolon (;). If you plan to use a semicolon in your Oracle stored procedure syntax, you must change the painter’s terminator character to something other than a semicolon to avoid conflicts. A good choice is the backquote ( ` ) character.

StepsTo change the default SQL terminator character in the Database painter:

  1. Connect to your Oracle database in DataWindow Designer as the System user.

    For instructions, see “Defining the Oracle database interface”.

  2. Open the Database painter.

  3. Select Design>Options from the menu bar.

    The Database Preferences property sheet displays. If necessary, click the General tab to display the General property page.

  4. Type the character you want (for example, a backquote) in the SQL Terminator Character box.

  5. Click Apply or OK.

    The SQL Terminator Character setting is applied to the current connection and all future connections (until you change it).

Creating the stored procedure

After setting up the Database painter, you can create an Oracle stored procedure that has a result set as an IN OUT (reference) parameter. DataWindow Designer retrieves the result set to populate a DataWindow object.

There are many ways to create stored procedures with result sets. The following procedure describes one possible method that you can use.

For information about when you can use stored procedures with single and multiple result sets, see “What you can do with Oracle stored procedures”.

StepsTo create Oracle stored procedures with result sets:

  1. Make sure your Oracle user account has the necessary database access and privileges to access Oracle objects (such as tables and procedures).

    Without the appropriate access and privileges, you will be unable to create Oracle stored procedures.

  2. Assume the following table named tt exists in your Oracle database:

    a

    b

    c

    1

    Newman

    sysdate

    2

    Everett

    sysdate

  3. Create an Oracle package that holds the result set type and stored procedure. The result type must match your table definition.

    For example, the following statement creates an Oracle package named spm that holds a result set type named rctl and a stored procedure named proc1. The tt%ROWTYPE attribute defines rctl to contain all of the columns in table tt. The procedure proc1 takes one parameter, a cursor variable named rc1 that is an IN OUT parameter of type rctl.

    CREATE OR REPLACE PACKAGE spm
       IS TYPE rctl IS REF CURSOR
       RETURN tt%ROWTYPE;
       PROCEDURE proc1(rc1 IN OUT rctl);END;`
    
  4. Create the Oracle stored procedure separately from the package you defined.

    The following example shows how to create a stored procedure named spm_proc 1 that returns a single result set.

    The IN OUT specification means that DataWindow Designer passes the cursor variable (rc1 or rc2) by reference to the Oracle procedure and expects the procedure to open the cursor. After the procedure call, DataWindow Designer fetches the result set from the cursor and then closes the cursor.

    spm_proc1 example for DataWindow objects The following statements create spm_proc1 which returns one result set. You can use this procedure as the data source for a DataWindow object in DataWindow Designer.

    CREATE OR REPLACE PROCEDURE spm_proc1(rc1 IN OUT      spm.rctl)
    AS
    BEGIN
       OPEN rc1 FOR SELECT * FROM tt;END;`
    
     
    

NoteError checking If necessary, check the Oracle system table public.user_errors for a list of errors.

Creating the DataWindow object

After you create the stored procedure, you can define the DataWindow object that uses the stored procedure as a data source.

You can use Oracle stored procedures that return a single result set in a DataWindow object.

The following procedure assumes that your Oracle stored procedure returns only a single result set.

StepsTo create a DataWindow object using an Oracle stored procedure with a result set:

  1. Select a presentation style on the DataWindow page of the New dialog box and click OK.

  2. Select the Stored Procedure icon and click OK.

    The Select Stored Procedure wizard page displays, listing the stored procedures available in your database.

  3. Select the stored procedure you want to use as a data source, and click Next.

  4. Complete the wizard to define the DataWindow object.

    When you preview the DataWindow object or call Retrieve, DataWindow Designer fetches the result set from the cursor in order to populate the DataWindow object. If you selected Retrieve on Preview on the Choose Data Source page in the wizard, the result set displays in the Preview view when the DataWindow opens.