我试图在plsql中创建2个包体。这是我的代码:
SET SERVEROUTPUT ON
CREATE OR REPLACE PACKAGE p_locations
AS
FUNCTION f_distance(Lat1 IN NUMBER, Lon1 IN NUMBER, Lat2 IN NUMBER, Lon2 IN NUMBER, Radius IN NUMBER DEFAULT 6387.7) return number;
END p_locations;
/
CREATE OR REPLACE PACKAGE BODY p_locations
AS
FUNCTION f_distance (Lat1 IN NUMBER, Lon1 IN NUMBER, Lat2 IN NUMBER, Lon2 IN NUMBER, Radius IN NUMBER DEFAULT 6387.7)
RETURN NUMBER
IS
-- Convert degrees to radians
DegToRad NUMBER := 57.29577951;
BEGIN
RETURN(NVL(Radius,0) * ACOS((sin(NVL(Lat1,0) / DegToRad) * SIN(NVL(Lat2,0) / DegToRad)) +
(COS(NVL(Lat1,0) / DegToRad) * COS(NVL(Lat2,0) / DegToRad) *
COS(NVL(Lon2,0) / DegToRad - NVL(Lon1,0)/ DegToRad))));
END f_distance;
END p_locations;
/
CREATE OR REPLACE PACKAGE p_winkel
AS
FUNCTION changeOpeningstijd("id" IN number) RETURN boolean;
END p_winkel;
/
CREATE OR REPLACE PACKAGE BODY p_winkel
AS
FUNCTION changeOpeningstijd("id" IN number)
RETURN boolean
IS
dbms_output.put_line('dit is uitgevoerd');
return true;
END changeOpeningstijd;
END p_winkel;
当我跑这个时,我收到3次PLS-00103错误。第一个是在第6,16行,并说遇到符号“。”期待以下之一:constant exception <an identifier> <a double-quoted delimited-identifier> table long double ref char time timestamp interval date binary national character nchar The symbol "<an identifier>" was substituted for "." to continue.
奇怪的是,当我评论出第二个包体时,一切正常。虽然错误是在第一个包定义的开头。
我在这里做了一些愚蠢的错误,或者你不能在一个会话中创建两个包,或者在这里发生了什么,因为我在这些错误中没有看到任何逻辑。
答案 0 :(得分:1)
您只是错过了BEGIN
关键字:
CREATE OR REPLACE PACKAGE BODY p_winkel
AS
FUNCTION changeOpeningstijd("id" IN number)
RETURN boolean
IS
BEGIN ---- this was missing
dbms_output.put_line('dit is uitgevoerd');
return true;
END changeOpeningstijd;
END p_winkel;
/
PL / SQL错误中的行号是指PL / SQL块(在本例中是包)引起的;它不是组合脚本中的行号,就像普通SQL错误的情况一样。
当您使用run script
运行时,会报告三个错误,而不仅仅是您引用的错误;另外两个都提到begin
:
Errors: check compiler log
6/16 PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national character
nchar
The symbol "<an identifier>" was substituted for "." to continue.
8/3 PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
The symbol "begin was inserted before "END" to continue.
9/13 PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin end function pragma procedure
正如Ben提到的,在每个spec / body定义之后添加show errors
以突出显示错误的位置是个好主意;但您也可以查询user_errors
视图以查看与每个无效对象相关的错误。