我创建了以下包和包体:
CREATE OR REPLACE PACKAGE interest_calculation IS
interest_rate number(2,3) := 0.5;
FUNCTION interests (ID IN char)
RETURN number;
END interest_calculation;
/
CREATE OR REPLACE PACKAGE BODY interest_calculation
IS
FUNCTION interests
(ID IN char)
RETURN number
IS
CURSOR ecursor IS
SELECT l.borrower_id, l.shiffer, l.date, l.return_date, r.price
FROM loans l, books r
WHERE l.shiffer=r.shiffer AND borrower_id = ID;
kirje ecursor%ROWTYPE;
summed number(4,2) := 0;
interest number(4,2);
period integer;
BEGIN
FOR kirje IN ecursor LOOP
period := kirje.return_date - kirje.date;
IF period < 15 THEN
interest := 0;
ELSE
interest := (period - 14) * kirje.price * (interest_rate/100) ;
END IF;
summed := summed + interest;
END LOOP;
RETURN summed;
END;
END interest_calculation;
/
当我调用包函数时:
execute interest_calculation.interests('37904010329');
我收到错误:
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00221: 'INTERESTS' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
为什么不返回功能值?我是否必须向包头添加一个过程,以便返回函数值?
我非常感谢您提供的任何帮助。
答案 0 :(得分:1)
您可以对程序使用execute关键字。在包中你创建了一个函数。要获得结果,您应该按以下格式执行该功能。
select interest_calculation.interests('37904010329')
from dual;
必须从SQL或PL / SQL语句中调用函数,其中函数返回的值被使用 - 即,分配给变量,作为参数传递等。