Da du bare vil teste funktionen, kan du bruge en anonym PL/SQL-blok til at kalde den og tildele dens resultat til en matchende rækketypevariabel, f.eks.:
declare
l_row mytable%rowtype;
begin
-- call the function and assign the result to a variable
l_row := mypackage.myfunction(1, 2, 3);
-- do something with the result
dbms_output.put_line(l_row.some_columns);
end;
/
Hurtig demo med et sammensat bord og udvidet funktion:
create table mytable (col1, col2, col3, col4, col5) as
select 1, 2, 3, 'test', sysdate from dual;
create or replace package mypackage as
function myfunction (param1 number, param2 number, param3 number)
return mytable%rowtype;
end mypackage;
/
create or replace package body mypackage as
function myfunction (param1 number, param2 number, param3 number)
return mytable%rowtype is
l_row mytable%rowtype;
begin
select * into l_row
from mytable
where col1 = param1
and col2 = param2
and col3 = param3;
return l_row;
end myfunction;
end mypackage;
/
Opkald fra SQL får den samme fejl, som du ser nu:
select mypackage.myfunction(1, 2, 3) from dual;
SQL Error: ORA-06553: PLS-801: internal error [55018]
Men med en blok (kør her gennem SQL Developer med output aktiveret):
set serveroutput on
declare
l_row mytable%rowtype;
begin
-- call the function and assign the result to a variable
l_row := mypackage.myfunction(1, 2, 3);
-- do something with the result
dbms_output.put_line(l_row.col4 ||':'|| l_row.col5);
end;
/
test:2019-04-29
PL/SQL procedure successfully completed.