PLS-00103:遇到符号“;”预期以下情况之一时:
Posted
技术标签:
【中文标题】PLS-00103:遇到符号“;”预期以下情况之一时:【英文标题】:PLS-00103: Encountered the symbol ";" when expecting one of the following: 【发布时间】:2013-11-18 21:50:28 【问题描述】:我的代码有什么问题
SQL> declare
2 mark number :=50;
3 begin
4 mark :=& mark;
5 if (mark between 85 and 100)
6 then
7 dbms_output.put_line('mark is A ');
8 else if (mark between 50 and 65) then
9 dbms_output.put_line('mark is D ');
10 else if (mark between 66 and 75) then
11 dbms_output.put_line('mark is C ');
12 else if (mark between 76 and 84) then
13 dbms_output.put_line('mark is B');
14 else
15 dbms_output.put_line('mark is F');
16 end if;
17 end;
18 /
Enter value for mark: 65
old 4: mark :=& mark;
new 4: mark :=65;
end;
*
第 17 行的错误: ORA-06550:第 17 行,第 4 列: PLS-00103:遇到符号“;”当期待以下之一时: 如果
【问题讨论】:
【参考方案1】:问题在于 else 和 if 是这里的两个运算符。由于您打开一个新的“如果”,因此您需要一个相应的“结束如果”。
因此:
declare
mark number :=50;
begin
mark :=& mark;
if (mark between 85 and 100) then
dbms_output.put_line('mark is A ');
else
if (mark between 50 and 65) then
dbms_output.put_line('mark is D ');
else
if (mark between 66 and 75) then
dbms_output.put_line('mark is C ');
else
if (mark between 76 and 84) then
dbms_output.put_line('mark is B');
else
dbms_output.put_line('mark is F');
end if;
end if;
end if;
end if;
end;
/
您也可以使用 elsif:
declare
mark number :=50;
begin
mark :=& mark;
if (mark between 85 and 100)
then
dbms_output.put_line('mark is A ');
elsif (mark between 50 and 65) then
dbms_output.put_line('mark is D ');
elsif (mark between 66 and 75) then
dbms_output.put_line('mark is C ');
elsif (mark between 76 and 84) then
dbms_output.put_line('mark is B');
else
dbms_output.put_line('mark is F');
end if;
end;
/
【讨论】:
【参考方案2】:IF 语句在PL/SQL
中有这些形式:
IF THEN
IF THEN ELSE
IF THEN ELSIF
您使用了elseif
,这在PL/SQL 方面是错误的。这需要替换为ELSIF
。
DECLARE
mark NUMBER :=50;
BEGIN
mark :=& mark;
IF (mark BETWEEN 85 AND 100) THEN
dbms_output.put_line('mark is A ');
elsif (mark BETWEEN 50 AND 65) THEN
dbms_output.put_line('mark is D ');
elsif (mark BETWEEN 66 AND 75) THEN
dbms_output.put_line('mark is C ');
elsif (mark BETWEEN 76 AND 84) THEN
dbms_output.put_line('mark is B');
ELSE
dbms_output.put_line('mark is F');
END IF;
END;
/
【讨论】:
以上是关于PLS-00103:遇到符号“;”预期以下情况之一时:的主要内容,如果未能解决你的问题,请参考以下文章