1. Create a Table object type.
To return a Table object in Oracle, you must customize a table type as follows:
Create or Replace type t_table is table of number;
When the above type is defined, the function uses a table that can return a column, and if more than one column is required, you need to define an object type first. Then replace the object type with the number in the above statement;
Define the object type:
Create or replace type Obj_table as Object
(
ID int,
Name VARCHAR2 (50)
)
The definition statement that modifies the Table object type is as follows:
Create or Replace type t_table is table of obj_table;
2. Create a demo function
In the definition of a function, you can use the Pipelined table function and the normal way, the following provides two ways to use the code:
1), pipelined table function mode:
Create or Replace function F_pipe (s number)
return t_table pipelined
As
V_obj_table obj_table;
Begin
For I in 1..s loop
V_obj_table: = Obj_table (I,to_char (i*i));
Pipe row (v_obj_table);
End Loop;
Return
End F_pipe;
Note: The way the pipeline must end with an empty return.
The function is called in the following way:
SELECT * FROM Table (F_pipe (5));
2), The ordinary way:
Create or Replace function F_normal (s number)
Return t_table
As
RS t_table:= t_table ();
Begin
For I in 1..s loop
Rs.extend;
RS (rs.count): = Obj_table (rs.count, ' name ' | | To_char (Rs.count));
--rs (Rs.count). Name: = RS (rs.count). Name | | ' XXXX ';
End Loop;
Return RS;
End F_normal;
After initializing the value, you can modify it as you would like to gaze at the line.
The method is called as follows:
SELECT * FROM Table (F_normal (5));
ORACLE table Function Implementation