Home » SQL & PL/SQL » SQL & PL/SQL » Returning a sys_refcursor from an explicit cursor (11.2)
Returning a sys_refcursor from an explicit cursor [message #629733] Mon, 15 December 2014 13:56 Go to next message
tmcallister
Messages: 107
Registered: December 2007
Senior Member
I'm trying to return a sys_refcursor from an explicit cursor rather than an implicit one; but the syntax is destroying me and google isn't my friend today.

Here are some trivial examples. I don't like the first one in my code since there is some pretty complicated logic and long queries and mixing them together is ugly. I don't like the second because I have a general dislike for dynamic queries unless they are doing something extremely useful, and this doesn't qualify. I don't like the third since I can't figure out the syntax.

Help please? Thanks!

/* Formatted on 12/15/2014 12:50:37 PM (QP5 v5.256.13226.35538) */
CREATE OR REPLACE PROCEDURE rc1(rc OUT SYS_REFCURSOR) AS
BEGIN
  OPEN rc FOR
    SELECT       ROWNUM
    FROM         DUAL
    CONNECT BY   LEVEL < 11;
END;
/

CREATE OR REPLACE PROCEDURE rc2(rc OUT SYS_REFCURSOR) AS
  sql_stmt   VARCHAR2(100) := 'SELECT       ROWNUM
     FROM         DUAL
     CONNECT BY   LEVEL < 11';
BEGIN
  OPEN rc FOR sql_stmt;
END;
/

CREATE OR REPLACE PROCEDURE rc3(rc OUT SYS_REFCURSOR) AS
  CURSOR c1  IS
    SELECT       ROWNUM
    FROM         DUAL
    CONNECT BY   LEVEL < 11;
BEGIN
  NULL;
END;
/
Re: Returning a sys_refcursor from an explicit cursor [message #629741 is a reply to message #629733] Mon, 15 December 2014 14:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

There is no difference between 1 and 2 but the fact that in 1 PL/SQL can verify the syntax (basic) and the semantic (does the object exist, are you allowed to refer it...) at compile time when it is done at execution time in 2.

I don't think you can do it with 3.

Re: Returning a sys_refcursor from an explicit cursor [message #641757 is a reply to message #629733] Fri, 21 August 2015 10:36 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Any feedback?

Previous Topic: Creating String
Next Topic: Update statement where update exists.
Goto Forum:
  


Current Time: Thu Apr 25 05:00:48 CDT 2024