Home » Other » Client Tools » execute a procedure returning ref cursor in toad
execute a procedure returning ref cursor in toad [message #247191] Mon, 25 June 2007 00:38 Go to next message
basirana
Messages: 25
Registered: July 2006
Junior Member
How to execute a procedure returning ref cursor in toad?

example

CREATE OR REPLACE PACKAGE REF_CURSOR_TEST IS

TYPE T_ACCOUNTS_CURSOR IS REF CURSOR;

PROCEDURE GET_ACCOUNTS_PROCEDURE (P_ACCOUNTS OUT T_ACCOUNTS_CURSOR);

END REF_CURSOR_TEST;
/

CREATE OR REPLACE PACKAGE BODY REF_CURSOR_TEST IS

PROCEDURE GET_ACCOUNTS_PROCEDURE (
P_ACCOUNTS OUT T_ACCOUNTS_CURSOR

) AS
BEGIN
OPEN P_ACCOUNTS FOR
SELECT
Account_ID as Id,
Account_FirstName as FirstName,
Account_LastName as LastName,
Account_Email as EmailAddress

FROM Accounts
ORDER BY Account_ID;
END GET_ACCOUNTS_PROCEDURE;

END REF_CURSOR_TEST;

/


Here procedure returning ref cursor. How to debug this procedure in Toad.
Re: execute a procedure returning ref cursor in toad [message #247673 is a reply to message #247191] Tue, 26 June 2007 13:52 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Of course you start by reading the help "REF CURSOR Results Window" or do it the old pl/sql way.

Enable DBMS output.
create table t1 (col1 varchar2(10), col2 varchar2(10));
insert into t1 values ('FirstCol', 'SecondCol');

CREATE OR REPLACE PACKAGE ref_cur_tst
IS
   -- weak ref cursor
   TYPE t_cur IS REF CURSOR; 

   PROCEDURE get_t1 (cv_cur IN OUT t_cur, p_col IN varchar2);
END;
/
CREATE OR REPLACE PACKAGE BODY ref_cur_tst
AS
   PROCEDURE get_t1 (cv_cur IN OUT t_cur, p_col IN varchar2)
   IS
   BEGIN
      OPEN cv_cur FOR 'SELECT '||p_col||' FROM t1';
   END;
END;
/


DECLARE
   a       varchar2(10);
   cv_c1   ref_cur_tst.t_cur;
   p_col  varchar2(20) := 'COL1';
BEGIN
   ref_cur_tst.get_t1 (cv_c1, p_col);

   LOOP
      FETCH cv_c1 INTO a;
      EXIT WHEN cv_c1%NOTFOUND;
      DBMS_OUTPUT.put_line (a);
   END LOOP;
   CLOSE cv_c1;
END;
/

Previous Topic: SQLPlus - How to hide the results during a SQL File exection
Next Topic: set scan off error
Goto Forum:
  


Current Time: Sun Dec 22 20:45:11 CST 2024