Skip to Main Content
  • Questions
  • Return Multiple Records in a Stored Procedure

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Kathy.

Asked: December 31, 2001 - 4:49 pm UTC

Last updated: December 17, 2018 - 2:13 am UTC

Version: Oracle 8i

Viewed 10K+ times! This question is

You Asked

I need to return the results of a query (multiple records) using a stored procedure. I know I can do it using a cursor and walking through each record one by one. It seems like there would be an easier way to return a "record set" using a stored procedure. I've tried "Select into" statement can only return one record.
Create Procedure GetChildren
(
lngParentID IN tblTree.ParentID%type,
p_ParentID OUT tblTree.ID%type,
p_ID OUT tblTree.ID%type,
p_Description OUT tblTree.Description%type,
p_NodeType OUT tblTree.NodeType%type
)
IS
BEGIN
SELECT ID, ParentID, Description, NodeType
INTO p_ParentID, p_ID, p_Description, p_NodeType
FROM tblTree
WHERE ParentID=lngParentID;
IF SQL%NOTFOUND THEN
RAISE_APPLICATION_ERROR(-20001, 'No records found');
END IF;
END;



and Tom said...

see the link below for the complete solution with examples in many languages.

https://asktom.oracle.com/pls/apex/asktom.search?file=Results#presentation-downloads-reg

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Result Set

Kathy Overcash, December 31, 2001 - 8:57 pm UTC

Thanks a million. That's exactly what I needed.

Parag

Parag, January 01, 2002 - 7:07 am UTC

Glad to read ur Ans. Is it possible to return Multiple Cursor's from Stored Procedure/Function.

Ex u have shonw here is returning One Ref-Curosr ( Which can hold Multiple Rows & Columns ) , Instead of returning One Ref-Cursors , We wanted to return Multiple Ref-Cursers.

Secondly , How to Eexcute the same at PL-SQL Level. Beca u have shown same at SQL PLUS Level.

Regards

Tom Kyte
January 01, 2002 - 11:31 am UTC

You can return as many as you like, you can use IN OUT parameters of a ref cursor type and return as many (or as few) as you like in a single call.

I didn't show a PLSQL example cause I thought that was sort of self evident? Its a cursor, after you open it, just fetch from it if you want to process it in plsql. Its not any different from any other cursor at that point.



Broken link

Nick, December 14, 2018 - 12:01 pm UTC

Connor McDonald
December 17, 2018 - 2:13 am UTC

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library