oracle PLS-00103:遇到符号“;” 当期待以下之一时:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20058685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:21:46  来源:igfitidea点击:

PLS-00103: Encountered the symbol ";" when expecting one of the following:

oracleplsqlsyntax-error

提问by Moh-ksa Madinah

what is wrong in my code

我的代码有什么问题

    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;
   *

ERROR at line 17: ORA-06550: line 17, column 4: PLS-00103: Encountered the symbol ";" when expecting one of the following: if

第 17 行错误:ORA-06550:第 17 行,第 4 列:PLS-00103:遇到符号“;” 当期待以下之一时:如果

回答by Richard

The problem is that the elseand ifare two operators here. Since you open a new 'if' you need a corresponding 'end if'.

问题是这里的elseif是两个运算符。由于您打开了一个新的“if”,因此您需要一个相应的“end if”。

Thus:

因此:

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;
/

Alternatively you can use elsif:

或者,您可以使用 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;
/

回答by Dulith De Costa

The IF statement has these forms in PL/SQL:

IF 语句具有以下形式PL/SQL

IF THEN

IF THEN ELSE

IF THEN ELSIF

You have used elseifwhich in terms of PL/SQL is wrong. That need to be replaced with ELSIF.

你用过elseifwhich 就 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;
/