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

  • Home
  • SEARCH
  • 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 8981181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:16:10+00:00 2026-06-15T20:16:10+00:00

I’m trying to create a stored function in oracle that returns multiple rows. My

  • 0

I’m trying to create a stored function in oracle that returns multiple rows.

My question is very similar to this one except that I want to fetch a select * query

In a nutshell, I want to create a function which returns the result of this query

select * from t_email_queue

What I’ve tried is this :

create or replace
PACKAGE email_queue AS 

  type t_email_queue_type is table of T_EMAIL_QUEUE%ROWTYPE;  

  FUNCTION lock_and_get return t_email_queue_type;

END email_queue;

create or replace
PACKAGE BODY email_queue AS 

    FUNCTION lock_and_get RETURN t_email_queue_type AS 
      queue_obj t_email_queue_type;

      cursor c (lockid in varchar2) is select * from t_email_queue where lockedby = lockid;
      lockid varchar2(100) := 'alf';
    BEGIN

      OPEN c(lockid);
      FETCH c bulk collect INTO queue_obj;

      return queue_obj;

    END lock_and_get;

END email_queue;

The package compiles just fine but when I try to call it with this query

select * from table(email_queue.lock_and_get);

Oracle throws the following error

ORA-00902: invalid datatype
00902. 00000 -  "invalid datatype"
*Cause:    
*Action:
Error at Line: 1 Column: 20

I think Oracle want me to create my return type at the schema level but when I try to do

create type t_email_queue_type is table of T_EMAIL_QUEUE%ROWTYPE;  

Oracle complains

Type IMAIL.T_EMAIL_QUEUE_TYPE@imail dev
Error(1): PL/SQL: Compilation unit analysis terminated
Error(2,37): PLS-00329: schema-level type has illegal reference to IMAIL.T_EMAIL_QUEUE

Can someone point me to the right direction? What am I missing here?

Thanks for reading!

  • 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-06-15T20:16:12+00:00Added an answer on June 15, 2026 at 8:16 pm

    with SQL types you cant do %ROWTYPE, you’d have to type each column to match the table*.

    *sys.anydataset aside. but going down that route is a lot more complex coding.

    e.g. if your table was

    create table foo (id number, cola varchar2(1));
    

    then

    create type email_queue_type is object (id number, cola varchar2(1));
    /
    create type t_email_queue_type as table of email_queue_type;
    /
    

    and use that table email_queue_type_tab as the output from your function.

    but i’d recommend a pipelined function, as your current code isn’t scalable.

    eg:

    SQL> create table foo (id number, cola varchar2(1));
    
    Table created.
    
    SQL>
    SQL> create type email_queue_type is object (id number, cola varchar2(1));
      2  /
    
    Type created.
    
    SQL> create type t_email_queue_type as table of email_queue_type;
      2  /
    
    Type created.
    
    SQL> insert into foo select rownum, 'a' from dual connect by level <= 10;
    
    10 rows created.
    
    SQL>
    SQL> create or replace PACKAGE email_queue AS
      2
      3
      4    FUNCTION lock_and_get return t_email_queue_type pipelined;
      5
      6  END email_queue;
      7  /
    
    Package created.
    
    SQL> create or replace PACKAGE BODY email_queue AS
      2
      3      FUNCTION lock_and_get RETURN t_email_queue_type pipelined AS
      4        queue_obj t_email_queue_type;
      5
      6      BEGIN
      7
      8       for r_row in (select * from foo)
      9              loop
     10                pipe row(email_queue_type(r_row.id, r_row.cola));
     11              end loop;
     12
     13      END lock_and_get;
     14
     15  END email_queue;
     16  /
    
    Package body created.
    
    SQL> select * from table(email_queue.lock_and_get());
    
            ID C
    ---------- -
             1 a
             2 a
             3 a
             4 a
             5 a
             6 a
             7 a
             8 a
             9 a
            10 a
    
    10 rows selected.
    
    SQL>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.