Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620156
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:31:20+00:00 2026-05-22T02:31:20+00:00

I wanted to have a function in PLSQL that would return an set of

  • 0

I wanted to have a function in PLSQL that would return an set of numbers, and then have a for loop that would iterate over that dataset and do something with it.

Any suggestions ? Does the function need to be a pipeline function for it to be used in the for loop? Do I need to create a new type even though Im just returning numbers?

Thanks!

 CREATE OR REPLACE PACKAGE BODY someBody AS

      FUNCTION getListOfNumbers RETURN someList IS -- what type do I return ??
      BEGIN
        RETURN SELECT SID FROM V$SESSION;  -- Not sure what do here ??
      END;

      PROCEDURE soSomeStuff IS
      BEGIN
        FOR rec IN(getListOfNumbers)  -- how do I select from the function?
        LOOP
          dbms_output.put_line(rec);
        END LOOP;
      END;
  END;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:31:20+00:00Added an answer on May 22, 2026 at 2:31 am

    You would need to declare a collection type:

    SQL> CREATE OR REPLACE PACKAGE my_package AS
      2  
      3     TYPE someList IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      4  
      5     FUNCTION getListOfNumbers RETURN someList;
      6     PROCEDURE soSomeStuff;
      7  
      8  END my_package;
      9  /
    
    Package created
    

    You would then use the defined type like this:

    SQL> CREATE OR REPLACE PACKAGE BODY my_package AS
      2  
      3     FUNCTION getListOfNumbers RETURN someList IS
      4        l_list someList;
      5     BEGIN
      6        SELECT SID BULK COLLECT INTO l_list FROM V$SESSION;
      7        RETURN l_list;
      8     END;
      9  
     10     PROCEDURE soSomeStuff IS
     11        l_list someList;
     12     BEGIN
     13        l_list := getListOfNumbers;
     14        FOR i IN 1..l_list.count LOOP
     15           dbms_output.put_line(l_list(i));
     16        END LOOP;
     17     END;
     18  
     19  END my_package;
     20  /
    
    Package body created
    
    SQL> exec my_package.soSomeStuff;
    
    284
    285
    287
    288
    [...]
    PL/SQL procedure successfully completed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I wanted to have an application that could easily switch the DB
For example <script> function foo(){...} </script> <div><script>foo();</script></div> <span><script>foo();</script></span> and I wanted to have foo
I have a function that changes the hash in the url and inserts/removes a
Ok so say I have a function that looks for a specific word in
I have been using anonymous namespaces to store local data and functions and wanted
Say I wanted to have a project, and one-to-many with to-do items, and wanted
If I wanted to have Python distributed across multiple processors on multiple computers, what
Ruby is preinstalled on my Mac and so I wanted to have a look
I've been working on a project in Delphi 7 where I wanted to have
Iam a great fan of javascript frameworks especially jQuery .I have always wanted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.