Suppose an application has to execute this statement...
select last_name from employees where department_id = :department_id...on behalf of the user, repeatedly for different values of :department_id. The recommended program design looks like this...
| task | Dbms_Sql calls |
| set up for the statement and do the the define-binding | Open_Cursor Parse Define_Column* |
| for each :department_id do the in-binding and establish the read-consistent snapshot for the query |
Bind_Variable* Execute |
| loop until no more data fetch the next row end loop |
Fetch_Rows Column_Value* |
| when no more :department_id values free the resources used by the cursor |
Close_Cursor |
The * means that this call may be made several times to process one SQL statement.
To test this, create two schemas programmer and observer.
Now create the package Employees_Cur_Dbms_Sql which exposes this API: Set_Up_Statement, Fetch_All_Rows and Free_Resources.
The costs associated with the Dbms_Sql calls are thus...
The rationale for the cost-saving paradigm is that there is no need to incur the costs of Open_Cursor, Parse, Define_Column and Close_Cursor more than once when the only difference between successive SQL statements is the values of the in-bind variables. Saving these costs can deliver a significant performance benefit. (Of course the costs of Bind_Variable, Execute, Fetch_Rows and Column_Value must be re-incurred for each new value of :department_id.)