I am trying to create a stored function in oracle that returns multiple rows.
My question is very similar to this , except that I want to receive a select * request
In short, I want to create a function that returns the result of this query
select * from t_email_queue
I tried 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 request
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 wants 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 in the right direction? What am I missing here?
Thank you for reading!
source share