Question

I am trying to call a stored procedure in TOAD from PL/SQL that has both OUT parameters and a SYS_REFCURSOR. When I try to execute the block below, I get ORA-01008: not all variables bound but I cannot determine which is the issue. I am prompted with a form to bind rtnData, so it doesnt seem to be that one.

declare
    QueryTime DATE;
    ErrorNum NUMBER;
    ErrorDesc VARCHAR2(2000);
    type rtnData is ref cursor;
begin  
  MyProcedure(to_date('01/01/2010', 'MM/DD/YYYY'), QueryTime, ErrorNum, ErrorDesc, :rtnData);
  dbms_output.put_line(rdbQueryTime);
  dbms_output.put_line(rtnErrorNum);
  dbms_output.put_line(rtnErrorDesc);
end;
Was it helpful?

Solution

rtnData is declared in the PL/SQL block, so you don't have to treat it as a bind variable - so it should not have a colon in front of it.

But rtnData is declared as a type, not as a variable. You don't need your own type, so it should be:

declare
  QueryTime DATE;
  ErrorNum NUMBER;
  ErrorDesc VARCHAR2(2000);
  rtnData sys_refcursor;
begin
  MyProcedure(to_date('01/01/2010', 'MM/DD/YYYY'), QueryTime, ErrorNum,
    ErrorDesc, rtnData);
...

If you're prompted for a form to set rtnData you'll still get that error if you don't set it, or if the parameter is declared as OUT in the MyProcedure declaration.

To display the ref cursor in a data grid in Toad, I think you need this:

declare
  QueryTime DATE;
  ErrorNum NUMBER;
  ErrorDesc VARCHAR2(2000);
begin
  MyProcedure(to_date('01/01/2010', 'MM/DD/YYYY'), QueryTime, ErrorNum,
    ErrorDesc, :rtnData);
...

... and then execute as a script, and choose 'cursor' as the bind type when prompted. I'm not able to test that though. (This suggests it'll work, but not sure why it's declaring the type as it isn't used).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top