- Прежде всего, не используйте переменную строкового типа для числовой (
invoice_id_text
). В вашем случае лучше использовать процедуру вместо вызываемой функции (return_num_rows_function
), поскольку вам нужно вернуть два аргумента out.
Нельзя использовать оператор SQL Select без Group By
с объединенными и неагрегированными столбцами вместе ( т.е. неt использовать это:
Select count(*) invoice_id, line_item_description
into inv_id,line_item_desc
From invoice_line_items
Where invoice_id = inv_id;
)
Итак, попробуйте создать следующие процедуры:
SQL> CREATE OR REPLACE Procedure
return_num_rows_proc(
i_invoice_id invoice_line_items.invoice_id%type,
inv_id out pls_integer,
line_item_desc out invoice_line_items.line_item_description%type
) Is
Begin
for c in
(
Select line_item_description
into line_item_desc
From invoice_line_items
Where invoice_id = i_invoice_id
)
loop
line_item_desc := line_item_desc||' '||c.line_item_description;
inv_id := nvl(inv_id,0) + 1;
end loop;
End;
/
SQL> CREATE OR REPLACE Procedure
return_num_rows(
i_invoice_id pls_integer
) Is
inv_id pls_integer;
line_item_desc invoice_line_items.line_item_description%type;
Begin
return_num_rows_proc(i_invoice_id,inv_id,line_item_desc);
If inv_id is not null then
dbms_output.put_line('The number of rows returned:' || inv_id);
dbms_output.put_line('Item description(s):' || line_item_desc);
End if;
End;
/
и звоните как в вашем случае:
SQL> set serveroutput on;
SQL> execute return_num_rows(7);