加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle – PLS-00103:遇到以下其中一项时遇到符号“;”:

发布时间:2020-12-12 15:13:59 所属栏目:百科 来源:网络整理
导读:我的代码有什么问题 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
我的代码有什么问题
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

问题是else和if是两个运算符.由于你打开一个新的’if’,你需要一个相应的’end 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;
/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读