我正在尝试在Oracle中创建一个包,但是我收到以下错误:
PLS-00323 PLS-00371
包裹代码是:
CREATE OR REPLACE PACKAGE mahalanobis_distance_package AS
max_d NUMBER;
TYPE tbnumber IS
TABLE OF NUMBER INDEX BY PLS_INTEGER;
FUNCTION rel_mahalanobis_distance_aux_3 (
a NUMBER,
b1 NUMBER,
b2 NUMBER,
b3 NUMBER
) RETURN tbnumber;
END mahalanobis_distance_package;
/
CREATE OR REPLACE PACKAGE BODY mahalanobis_distance_package AS
max_d NUMBER;
TYPE tbnumber IS
TABLE OF NUMBER INDEX BY PLS_INTEGER;
FUNCTION rel_mahalanobis_distance_aux_3 (
a NUMBER,
b1 NUMBER,
b2 NUMBER,
b3 NUMBER
) RETURN tbnumber IS
tbnumber_obj tbnumber;
BEGIN
max_d := 0;
FOR j IN 1..3 LOOP
tbnumber_obj(j) := 0;
END LOOP;
tbnumber_obj(1) := abs(a - b1);
IF
tbnumber_obj(1) > max_d
THEN
max_d := tbnumber_obj(1);
END IF;
tbnumber_obj(2) := abs(a - b2);
IF
tbnumber_obj(2) > max_d
THEN
max_d := tbnumber_obj(2);
END IF;
tbnumber_obj(3) := abs(a - b3);
IF
tbnumber_obj(3) > max_d
THEN
max_d := tbnumber_obj(3);
END IF;
RETURN tbnumber_obj;
END rel_mahalanobis_distance_aux_3;
END mahalanobis_distance_package;
/
为什么我会收到这些错误?
提前致谢!
答案 0 :(得分:1)
答案 1 :(得分:0)
您已在包规范中声明了包变量和TYPE tbnumber。
从正文中删除这些声明,它将编译得很好。
虽然您会收到编译器警告(如果已启用)
Warning(2,11): PLW-06026: package specification exposes global variable
这是你的代码
create or replace PACKAGE mahalanobis_distance_package AS
max_d NUMBER;
TYPE tbnumber IS
TABLE OF NUMBER INDEX BY PLS_INTEGER;
FUNCTION rel_mahalanobis_distance_aux_3 (
a NUMBER,
b1 NUMBER,
b2 NUMBER,
b3 NUMBER
) RETURN tbnumber;
END mahalanobis_distance_package;
/
create or replace PACKAGE BODY mahalanobis_distance_package AS
FUNCTION rel_mahalanobis_distance_aux_3 (
a NUMBER,
b1 NUMBER,
b2 NUMBER,
b3 NUMBER
) RETURN tbnumber IS
tbnumber_obj tbnumber;
BEGIN
max_d := 0;
FOR j IN 1..3 LOOP
tbnumber_obj(j) := 0;
END LOOP;
tbnumber_obj(1) := abs(a - b1);
IF
tbnumber_obj(1) > max_d
THEN
max_d := tbnumber_obj(1);
END IF;
tbnumber_obj(2) := abs(a - b2);
IF
tbnumber_obj(2) > max_d
THEN
max_d := tbnumber_obj(2);
END IF;
tbnumber_obj(3) := abs(a - b3);
IF
tbnumber_obj(3) > max_d
THEN
max_d := tbnumber_obj(3);
END IF;
RETURN tbnumber_obj;
END rel_mahalanobis_distance_aux_3;
END mahalanobis_distance_package;
/