Using REFCURSOR Bind Variables
Using Scripts in SQL*Plus
5-23
create procedure p4 as
c1 sys_refcursor;
c2 sys_refcursor;
begin
open c1 for SELECT * FROM DEPT;
dbms_sql.return_result(c1);
open c2 for SELECT * FROM EMP;
dbms_sql.return_result(c2);
end;
/
Next, enter a PL/SQL block that uses the bind variable in an OPEN... FOR
SELECT
statement. This statement opens a cursor variable and executes a query. See the
Oracle
Database PL/SQL Language Reference for information
on the OPEN command and
cursor variables.
In this example we are binding the SQL*Plus
employee_info bind variable to the cursor
variable.
BEGIN
OPEN :employee_info FOR SELECT EMPLOYEE_ID,
SALARY
FROM EMP_DETAILS_VIEW WHERE JOB_ID='SA_MAN' ;
END;
/
The results from the SELECT statement can now be displayed in SQL*Plus with the
PRINT command.
PRINT employee_info
The PRINT statement also closes the cursor. To reprint the results, the PL/SQL block
must be executed again before using PRINT.
Do'stlaringiz bilan baham: