A solution follows below. To simplify I considered that its report function would return a table with the fields name and amount.
Solution link running on SQL Feedle: http://sqlfiddle.com/#! 4/4c06c/1/0
1) Create a type Object which contains a representation of the columns of the table to be returned by its function.
create or replace type t_linhas as object (
nome varchar2(30),
quantidade number
);
/
2) Create a type table. Note below that the table is formed by type line which has just been created.
create or replace type t_tabela_relatorio as table of t_linhas;
/
3) Create function by returning type t_tabulat_report that was created in the beginning
create or replace function fc_relatorio return t_tabela_relatorio as
v_ret t_tabela_relatorio;
cursor c_consulta_base_relatorio is
select 'Joao' as nome_cliente, 10 as qtd from dual union
select 'Pedro' as nome_cilente, 20 as qtd from dual union
select 'Isabel' as nome_ciente, 15 as qtd from dual;
begin
v_ret := t_tabela_relatorio();
for x in c_consulta_base_relatorio loop
v_ret.extend;
v_ret(v_ret.count) := t_linhas(x.nome_cliente,x.qtd);
end loop;
return v_ret;
end fc_relatorio;
/
3) Example of how to call the function:
SELECT * FROM TABLE(FC_RELATORIO())
Source: http://www.adp-gmbh.ch/ora/plsql/coll/return_table.html
And what is being put in table_name.column?
– Reginaldo Rigo
I don’t understand your question Reginaldo?
– Leonardo Nori
How is the command that is going to the bank?
– Reginaldo Rigo
In fact I have never seen this command for the creation of tables, nor do I know if it is possible. It is used in TRIGGERS or PROCEDURES for you to create variables. You create the 'plant' variable with the same type and size of the seat column.
– Reginaldo Rigo
This msm Reginaldo, I’m trying to make a function to return a table, only that the table does not exist in the database, so I would have to create a new table. Searching the internet find this example link
– Leonardo Nori
See the answer below and you should understand how to use.
– Reginaldo Rigo