Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function Return Type: Can it be plsql Table

Status
Not open for further replies.

jluost1

Programmer
Jun 8, 2001
78
US
An example:
----------------------
TYPE task_rec_type IS RECORD
(id NUMBER, name VARCHAR2(25))

TYPE task_tbl_type IS TABLE OF task_rec_type
INDEX BY BINARY_INTEGER;
---------------------

Question:

Can I have the function:

FUNCTION load_table(p_task_id IN NUMBER)
RETURN task_tbl_type IS ...
 
JLuost1,

Short answer: Yes, you may return a table from a function.

Proof of concept: Using your original code...

set serveroutput on
declare
TYPE task_rec_type IS RECORD (id NUMBER, name VARCHAR2(25));
TYPE task_tbl_type IS TABLE OF task_rec_type INDEX BY BINARY_INTEGER;
y task_tbl_type;
FUNCTION load_table (p_task_id IN NUMBER) RETURN task_tbl_type IS
x task_tbl_type;
begin
x(1).id := 1;
x(1).name := 'Text Line 1';
x(2).id := 2;
x(2).name := 'Text Line 2';
return x;
end;
begin
y := load_table (1);
dbms_output.put_line(y(1).id||': '||y(1).name);
dbms_output.put_line(y(2).id||': '||y(2).name);
end;
/
1: Text line 1
2: Text line 2
SQL>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top