Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Returning rows from stored proc

703083Mar 31 2011 — edited Apr 2 2011
Hello, this is the sample from the SQL Developer help to create proc:


CREATE OR REPLACE
PROCEDURE list_a_rating(in_rating IN NUMBER) AS
matching_title VARCHAR2(50);
TYPE my_cursor IS REF CURSOR;
the_cursor my_cursor;
BEGIN
OPEN the_cursor
FOR 'SELECT title
FROM books
WHERE rating = :in_rating'
USING in_rating;
DBMS_OUTPUT.PUT_LINE('All books with a rating of ' || in_rating || ':');
LOOP
FETCH the_cursor INTO matching_title;
EXIT WHEN the_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(matching_title);
END LOOP;
CLOSE the_cursor;
END list_a_rating;



You have to write a cursor just to display results from a query. To me this is whacked but I'll go with it. So what if you wanted to return that resultset or refcursor so it can be consumed by a calling application or procedure? I tried something like

CREATE OR REPLACE PROCEDURE list_a_rating(in_rating IN NUMBER, MatchingTitles OUT Ref Cursor)

but that's not compiling. How do you return data from a proc or function?

Thanks,
Ken
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2011
Added on Mar 31 2011
13 comments
2,705 views