【问题标题】:PLS-00103: Encountered the symbol "END" when expecting one of the following: . ; The symbol ";" was substituted for "END" to continuePLS-00103:在预期以下情况之一时遇到符号“END”:。 ;符号“;”被替换为“END”以继续
【发布时间】:2020-06-17 13:29:50
【问题描述】:

我写了以下程序:

create or replace procedure ADDPHONE(IDPELATH  in number,IDTHLEFWNO in number )
is
cursor cursor_number is select id_pelath  ,TelephoneNumber from PhoneNumbers
where id_pelath>2;
more_than_two_numbers exception;
begin
open cursor_number ;
fetch cursor_number into IDPELATH;
if id_pelath%FOUND then raise more_than_two_numbers
end if;
close cursor_number;
exception
when more_than_two_numbers then 
raise_application_error('Error');
END;
/

当我运行它时,我收到以下错误:

PLS-00103: Encountered the symbol "END" when expecting one of the following:     . ; 
The symbol ";" was substituted for "END" to continue.  

你能帮我找出错误吗?

【问题讨论】:

  • 请不要大喊大叫。
  • 如果 id_pelath%FOUND 然后提高 more_than_two_numbers ;
  • 程序中存在多个问题。输入参数从未被使用过,为什么需要它们?光标正在获取一个变量但是定义说两个?你的问题陈述是什么。

标签: plsql oracle11g compiler-errors


【解决方案1】:

程序中存在多个问题。

  1. 输入参数永远不会在正文中使用。
  2. 游标被声明为获取两个,但 FETCH 语句只获取一个。
  3. raise_application_error 使用不正确,它需要两个输入参数。

我已经修改了应该完成这项工作的代码,

 CREATE or REPLACE procedure ADDPHONE(IDPELATH  in number,IDTHLEFWNO in number)
is

    lv_cnt number(10):=0;
    more_than_two_numbers exception;

BEGIN 

    select COUNT(1) INTO lv_cnt 
    from PhoneNumbers
    where id_pelath  = IDPELATH
    and TelephoneNumber = IDTHLEFWNO;

    if (lv_cnt > 2) then 
        raise_application_error(-20001,'Error - More than two Numbers ');
    end if;

EXCEPTION
        WHEN OTHERS THEN
           raise_application_error(-20002,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    END ADDPHONE;


/

【讨论】:

  • 这个程序的重点是创建一个程序,它会显示在一个客户中插入了多少电话,如果超过 2 个,它将引发异常并且不允许您添加更多。我想用光标来做,但我失败了。我知道我有更多问题,但程序只显示这个。我对 pl/sql 不是很好,我还在学习
  • 游标用于处理多条记录。如果我正确理解了您的要求,则不需要光标。您尝试过答案部分中发布的程序吗?它不工作吗?
  • 如果我在它工作的最后删除了 when 语句,我不知道为什么我在输入“when”语句时会出错,但这很好,不是很大的损失,我只是删除了最后一部分。至于游标,我只是想尝试一下,看看我是否可以这样写。无论如何,感谢您的帮助和建议
  • 现在修改了代码,我错过了 EXCEPTION 位。很高兴它起作用了。
猜你喜欢
  • 1970-01-01
  • 2021-12-20
  • 2019-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-19
  • 2014-09-18
相关资源
最近更新 更多