A Sample Program 
The following sample code--a SQL script and a Pro*Ada program--demonstrate how you can use cursor variables in Pro*Ada. These sources are available on-line in your demo directory.

cursvar.sql 

CREATE OR REPLACE PACKAGE emp_demo_pkg AS
    TYPE emp_cur_type IS REF CURSOR RETURN emp%ROWTYPE;
    PROCEDURE open_cur (
        emp_cursor   IN OUT emp_cur_type,
        dept_num     IN     number);
END;
/  
  


CREATE OR REPLACE PACKAGE BODY emp_demo_pkg AS

    PROCEDURE open_cur (
        emp_cursor   IN OUT emp_cur_type, 
        dept_num     IN     number) IS

    BEGIN 
        OPEN emp_cursor FOR 
            SELECT * FROM emp
            WHERE deptno = dept_num
            ORDER BY ename ASC;
        END;
END;
/



cursvar.pad 

with text_io,
     integer_text_io,
     float_io;

procedure cursvar is

use text_io,
    integer_text_io,
    float_io;

-- TYPE declarations

type emp_info_type is
record
    emp_num        : integer;
    emp_name       : string(1..11);
    job            : string(1..10);
    manager        : integer;
    hire_date      : string(1..10);
    salary         : float;
    commission     : float;
    dept_num       : integer;
    
end record;
 
type emp_info_ind_type is
record
    emp_num_ind     : oracle.indicator;
    emp_name_ind    : oracle.indicator;
    job_ind         : oracle.indicator;
    manager_ind     : oracle.indicator;
    hire_date_ind   : oracle.indicator;
    salary_ind      : oracle.indicator;
    commission_ind  : oracle.indicator;
    dept_num_ind    : oracle.indicator;
end record;

-- VARIABLE declarations
SQL_ERROR    : exception;

    EXEC SQL BEGIN DECLARE SECTION;
uid           : string(1..11) := "Scott/Tiger";
emp_cursor    : oracle.cursor_def;
dept_num      : integer;
emp_info      : emp_info_type;
emp_info_ind  : emp_info_ind_type;

    EXEC SQL END DECLARE SECTION;

begin
    
-- Handle SQL errors.
    EXEC SQL WHENEVER SQLERROR raise SQL_ERROR;
    
-- Connect to Oracle.
    EXEC SQL CONNECT :uid;
 
-- Allocate the cursor variable.
    EXEC SQL ALLOCATE :emp_cursor;
 
-- Exit the inner loop when NO DATA FOUND.
    EXEC SQL WHENEVER NOT FOUND DO exit;


loop
    new_line;
    put("Enter department number  (0 to exit): ");
    get(dept_num);
    if (dept_num <= 0) then
        exit;
    end if;

        EXEC SQL EXECUTE
            begin
                emp_demo_pkg.open_cur(:emp_cursor, :dept_num);
            end;
        END-EXEC;

    new_line;
    put("For department: ");
    put(dept_num, width=>4);
    put_line(" --");
    new_line;
    put_line("ENAME             SALARY           COMMISSION");
    put_line("-----             ------           ----------");
    new_line;


-- Fetch each row in the EMP table into the emp_info record.
-- Note the use of a parallel indicator record.

    loop
        EXEC SQL FETCH :emp_cursor
            INTO :emp_info.emp_num
                   INDICATOR   :emp_info_ind.emp_num_ind,
                 :emp_info.emp_name
                   INDICATOR :emp_info_ind.emp_name_ind,
                 :emp_info.job
                   INDICATOR :emp_info_ind.job_ind,
                 :emp_info.manager
                   INDICATOR :emp_info_ind.manager_ind,
                 :emp_info.hire_date
                   INDICATOR :emp_info_ind.hire_date_ind,
                 :emp_info.salary
                   INDICATOR :emp_info_ind.salary_ind,
                 :emp_info.commission
                   INDICATOR :emp_info_ind.commission_ind,
                 :emp_info.dept_num
                   INDICATOR :emp_info_ind.dept_num_ind;
 
        put(emp_info.emp_name);
        put(emp_info.salary, fore=>10, aft=>2, exp=>0);
        if (emp_info_ind.commission_ind /= 0) then
            put_line("                 NULL");
        else
            put(emp_info.commission, fore=>18, aft=>2, exp=>0);
            new_line;
        end if;
    end loop; --inner loop

end loop;  -- outer loop
 
-- Close the cursor.
    EXEC SQL CLOSE :emp_cursor;

-- Handle SQL errors.
    exception
        when SQL_ERROR =>
            EXEC SQL WHENEVER SQLERROR CONTINUE;
            put_line("** ORACLE ERROR OCCURED **");
            put_line(ORACLE.ERROR.MESSAGE);
            EXEC SQL ROLLBACK RELEASE;
 
end cursvar;
