Output ref cursor in anonymous block

rjv_rnjn

Member
Hi,
I've just got started with Oracle & PL/SQL developer.
To test my code I write anonymous blocks and execute them to test their correctness. I've been testing this on Oracle SQL developer and my code would run as expected. But when I take the same code in PL/SQL developer it throws errors. The code is something like:

variable csr refcursor;
declare

myVar varchar2(100) ;

begin
myVar := 'test';
open :csr for
select * from employees where emp_name = myVar;
end;
/
print :csr;

The results come as expected in the Oracle SQL developer. But the same query in PL/SQL gives me "invalid sql statement".
As a variation I tried this:

declare
csr refcursor;
myVar varchar2(100) ;

begin
myVar := 'test';
open :csr for
select * from employees where emp_name = myVar;
end;
/
print :csr;
Then it gives me "PLS-00103: Encountered the symbol "/" If I remove that then it gets stuck at encountered the symbol "print".
Any ideas on how I can get this working?
Thanks.
 
The Test Script consists of an Anonymous PL/SQL Block and a list of bind variables and values. In the editor of the PL/SQL Block you can enter the following:

Code:
declare
  myVar varchar2(100);
begin
  myVar := 'test';
  open :csr for
    select * from employees where emp_name = myVar;
end;

No SQL*Plus commands like print or slashes are allowed, just PL/SQL. The :csr variable can be declared in the variable list, with data type "Cursor". After executing the Test Script, press the value button of the variable to open a window with the cursor result set.

See chapter 4 in the User's Guide for more details about the Test Window features.
 
Thank you Marco. The reference to chapter 4 was great; it got me going.

BTW, how did you put the code tag? I didn't see any such icon on the editor window.
Edit: Got it!
 
Last edited:
A code block can be created like this (without the spaces in the tags):

[ code ]
your code lines here
[ /code ]

See the "What UBBCode can I use in my posts?" section from this FAQ for complete UBBCode information.
 
Back
Top