PLS-00103 同时创建 2 个包 PLSQL
PLS-00103 while creating 2 packages PLSQL
我正在尝试在 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.
奇怪的是,当我注释掉第二个包主体时,一切正常。虽然错误出现在第一个包定义的开头。
我是不是在做一些愚蠢的错误,或者你不能在一个会话中创建两个包,或者这里发生了什么,因为我没有看到这些错误中的任何逻辑。
您只是缺少 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
视图以查看与每个无效对象相关的错误。
我正在尝试在 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.
奇怪的是,当我注释掉第二个包主体时,一切正常。虽然错误出现在第一个包定义的开头。
我是不是在做一些愚蠢的错误,或者你不能在一个会话中创建两个包,或者这里发生了什么,因为我没有看到这些错误中的任何逻辑。
您只是缺少 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
视图以查看与每个无效对象相关的错误。