我试图创建一个包含函数和过程的包,遗憾的是我遇到了问题并且发生了以下错误
PLS-00330:无效使用类型名称或子类型名称编译失败,第11行(19:53:17)
PL / SQL:忽略语句
我已经阅读并完成了研究以尝试解决问题,但一直无法修复它。
包装规格:
create or replace package e_con_pack
AS
FUNCTION GET_LOCATION_namel (p_con_id in NUMBER, p_con_name out VARCHAR2)RETURN NUMBER;
PROCEDURE ADD_CONSULTANT ( p_con_id LDS_CONSULTANT.CONSULTANT_ID%type,
p_con_name LDS_CONSULTANT.CST_NAME%type,
p_con_start LDS_CONSULTANT.START_DATE%type,
p_con_end LDS_CONSULTANT.LEAVE_DATE%type,
p_con_loc LDS_CONSULTANT.LOCATION%type,
p_con_spec LDS_CONSULTANT.SPECIALIST_AREA%type);
PROCEDURE update_location(p_con_id IN
lds_consultant.consultant_id%type,
p_con_loc IN lds_consultant.location%type);
PROCEDURE delete_con (p_con_id IN
lds_consultant.consultant_id%type);
end e_con_pack;
包体:
create or replace PACKAGE BODY e_con_pack
AS
FUNCTION
GET_LOCATION_namel (p_con_id in NUMBER, p_con_name out VARCHAR2)
RETURN NUMBER IS
LOCATION VARCHAR2(30);
BEGIN
SELECT LOCATION INTO LOCATION FROM LDS_CONSULTANT WHERE CONSULTANT_ID = p_con_id;
SELECT CST_NAME INTO p_con_name FROM LDS_CONSULTANT WHERE CONSULTANT_ID = p_con_id;
RETURN NUMBER;
END GET_LOCATION_namel;
PROCEDURE ADD_CONSULTANT
( p_con_id LDS_CONSULTANT.CONSULTANT_ID%type,
p_con_name LDS_CONSULTANT.CST_NAME%type,
p_con_start LDS_CONSULTANT.START_DATE%type,
p_con_end LDS_CONSULTANT.LEAVE_DATE%type,
p_con_loc LDS_CONSULTANT.LOCATION%type,
p_con_spec LDS_CONSULTANT.SPECIALIST_AREA%type)
IS
BEGIN
INSERT INTO LDS_CONSULTANT (CONSULTANT_ID, CST_NAME, START_DATE, LEAVE_DATE, LOCATION, SPECIALIST_AREA)
VALUES (p_con_id, p_con_name, p_con_start, p_con_end, p_con_loc, p_con_spec);
END ADD_CONSULTANT;
PROCEDURE update_location (
p_con_id IN lds_consultant.consultant_id%type,
p_con_loc IN lds_consultant.location%type
)
IS
BEGIN
UPDATE lds_consultant
SET
location = p_con_loc
WHERE consultant_id = p_con_id;
END update_location;
PROCEDURE delete_con (
p_con_id IN lds_consultant.consultant_id%type )
As
Begin
Delete from LDS_CONSULTANT Where CONSULTANT_ID=p_con_id;
END delete_con;
END e_con_pack;
答案 0 :(得分:0)
针对包体的第11行报告错误,即
RETURN NUMBER;
Number是数据类型,而不是变量名称。目前尚不清楚你真正想要回到这里;当你在查询和捕捉它时,也许LOCATION
;但由于这是一个字符串,函数的返回类型也需要是一个字符串(即VARCHAR2
而不是NUMBER
)。也许:
create or replace PACKAGE BODY e_con_pack
AS
FUNCTION
GET_LOCATION_namel (p_con_id in NUMBER, p_con_name out VARCHAR2)
RETURN VARCHAR2 IS
LOCATION VARCHAR2(30);
BEGIN
SELECT LOCATION INTO LOCATION FROM LDS_CONSULTANT WHERE CONSULTANT_ID = p_con_id;
SELECT CST_NAME INTO p_con_name FROM LDS_CONSULTANT WHERE CONSULTANT_ID = p_con_id;
RETURN LOCATION;
END GET_LOCATION_namel;
甚至更好,使用列数据类型,就像您在其他地方一样:
create or replace PACKAGE BODY e_con_pack
AS
FUNCTION
GET_LOCATION_namel (p_con_id in NUMBER, p_con_name out VARCHAR2)
RETURN LDS_CONSULTANT.LOCATION%type IS
LOCATION LDS_CONSULTANT.LOCATION%type;
BEGIN
...
无论哪种方式,您都需要更改包规范以匹配。