레코드 유형의 테이블을 반환하는 패키지에 정의 된 함수를 테스트하려고 할 때 '표현식이 잘못된 유형입니다'라는 메시지가 표시됩니다.
헤더는 다음과 같습니다.
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;
/
그리고 여기에 본문이 있습니다.
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;
/
테스트하는 방법은 다음과 같습니다.
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;
/
패키지의 두 부분 모두 문제없이 컴파일됩니다.
전체 오류는 다음과 같습니다.
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
내가 뭔가를 놓치고 있습니까? 감사.
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;
/
시도해보세요.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다