Oracle - 'Expression is of wrong type' 返回包中记录类型表

Nel*_*SMG 1 oracle types function package

尝试测试在返回记录类型表的包中定义的函数时,我收到“表达式类型错误”。
这是标题:

create or replace package pck_prestamos is
type r_cuotas is record
    (saldo_capital number(12),
    amortizacion number(12),
    interes number(12),
    seguro_vida number(8),
    monto_cuota number(15),
    fecha_vencimiento date);
type t_cuotas is table of r_cuotas
    index by binary_integer;
--v_cuotas t_cuotas;
function f_calcular_cuotas(monto_p number,t_i_a number, plazo_p number, fecha_d date) return t_cuotas;
end;
/
Run Code Online (Sandbox Code Playgroud)

这是身体:

create or replace package body pck_prestamos is
function f_calcular_cuotas(monto_p number,t_i_a number, plazo_p number, fecha_d date) return t_cuotas is
    saldo_capital_ant number;
    amortizacion_capital_ant number;
    diferencia number;
    porc_seg_v gen_parametros.porc_seg_vida%type;
    v_cuotasf t_cuotas;
begin
    select porc_seg_vida into porc_seg_v
        from gen_parametros;
    for i in 1..plazo_p loop
        if i = 1 then 
            v_cuotasf(i).saldo_capital := monto_p;
            saldo_capital_ant := v_cuotasf(i).saldo_capital;
            amortizacion_capital_ant := monto_p/plazo_p;
        else
            v_cuotasf(i).saldo_capital := saldo_capital_ant - amortizacion_capital_ant;
            saldo_capital_ant := v_cuotasf(i).saldo_capital;
        end if;
        if i = plazo_p then
            diferencia := v_cuotasf(i).saldo_capital - amortizacion_capital_ant;
            v_cuotasf(i).amortizacion := (monto_p/plazo_p) + diferencia;
        else 
            v_cuotasf(i).amortizacion := monto_p/plazo_p;
        end if;
        v_cuotasf(i).interes := ((t_i_a/12)/100)*v_cuotasf(i).saldo_capital;
        v_cuotasf(i).seguro_vida := (porc_seg_v/100)*v_cuotasf(i).saldo_capital;
        v_cuotasf(i).monto_cuota := v_cuotasf(i).amortizacion + v_cuotasf(i).interes + v_cuotasf(i).seguro_vida;
        v_cuotasf(i).fecha_vencimiento := fecha_d + 30*i; 
    end loop;
    return v_cuotasf;
end;
end;
/
Run Code Online (Sandbox Code Playgroud)

这是我尝试测试它的方式:

declare
type r_cuotas is record
    (saldo_capital number(12),
    amortizacion number(12),
    interes number(12),
    seguro_vida number(8),
    monto_cuota number(15),
    fecha_vencimiento date);
type t_cuotas is table of r_cuotas
    index by binary_integer;
v_cuotas t_cuotas;
begin
v_cuotas := pck_prestamos.f_calcular_cuotas(10000000,10,18,sysdate);
end;
/
Run Code Online (Sandbox Code Playgroud)

包的两部分编译都没有问题。
完整的错误是:

ERROR at line 13:  
ORA-06550: line 13, column 13:  
PLS-00382: expression is of wrong type  
ORA-06550: line 13, column 1:  
PL/SQL: Statement ignored 
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?谢谢。

Bob*_*ica 6

从 Oracle 的角度来看,t_cuotas在您的测试块中声明的类型与在您的包中声明的类型不同,即使它们可能具有相同的元素并且对您和我来说“看起来”相同。您需要通过使用t_cuotas包名称对其进行限定来使用包中定义的:

declare
  v_cuotas pck_prestamos.t_cuotas;
begin
  v_cuotas := pck_prestamos.f_calcular_cuotas(10000000,10,18,sysdate);
end;
/
Run Code Online (Sandbox Code Playgroud)

试一试吧。