【问题标题】:Error : PLS-00103: Encountered the symbol "END" when expecting one of the following错误:PLS-00103:在预期以下情况之一时遇到符号“END”
【发布时间】:2013-03-23 06:07:56
【问题描述】:

我写了以下包和包体:

create or replace package discounts
is
g_id number := 7839;
discount_rate number := 0.0;
procedure display_price(p_price number);
end;
/
create or replace package body discounts
is
procedure display_price(p_price number)
is
  begin
     dbms_output.put_line('Discount rate 1:'||discount_rate); 
     dbms_output.put_line('Discounted '||to_char(p_price * nvl(discount_rate,0)));
     dbms_output.put_line('Discount rate 2:'||discount_rate); 
  end;
begin
  dbms_output.put_line('Discount rate 3:'||discount_rate); 
  discount_rate := 0.10;
  dbms_output.put_line('Discount rate 4:'||discount_rate); 
end;
/

写到“在会话中第一次调用包时,discount_rate 的值设置为 0.10”。我没有完全理解这一点,这就是为什么我每次都检查贴现率的值。我输入了以下内容来调用:

SQL> execute discounts.display_price(1000);
Discount rate 3:0
Discount rate 4:.1
Discount rate 1:.1
Discounted 100
Discount rate 2:.1

然后我又调用了变量:

  begin
    dbms_output.put_line('Discount rate :'||discounts.discount_rate);
  end;
  SQL> /
  Discount rate :.1

然后我键入“exit”关闭 SQL *PLUS。我再次打开 SQL *PLUS 并输入相同的代码:

  begin
    dbms_output.put_line('Discount rate :'||discounts.discount_rate);
  end;

我以为它不会初始化变量,但我得到了错误:

  ERROR at line 3:
  ORA-06550: line 3, column 1:
  PLS-00103: Encountered the symbol "END" when expecting one of the following:
  := . ( % ;
  The symbol ";" was substituted for "END" to continue.

什么是错误?我是准备认证考试的 PL/SQL 新手。

【问题讨论】:

    标签: plsql oracle10g sqlplus


    【解决方案1】:

    抱歉,我无法重现您显示的错误:

    C:\>sqlplus user/password
    
    SQL*Plus: Release 11.2.0.2.0 Production on Sat Mar 23 11:31:19 2013
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
    
    SQL> set serveroutput on
    SQL> execute discounts.display_price(1000);
    Discount rate 3:0
    Discount rate 4:.1
    Discount rate 1:.1
    Discounted 100
    Discount rate 2:.1
    
    PL/SQL procedure successfully completed.
    
    SQL> begin
      2    dbms_output.put_line('Discount rate :'||discounts.discount_rate);
      3  end;
      4  /
    Discount rate :.1
    
    PL/SQL procedure successfully completed.
    
    SQL> exit
    Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
    
    C:\>sqlplus user/password
    
    SQL*Plus: Release 11.2.0.2.0 Production on Sat Mar 23 11:31:50 2013
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
    
    SQL> set serveroutput on
    SQL> begin
      2    dbms_output.put_line('Discount rate :'||discounts.discount_rate);
      3  end;
      4  /
    Discount rate 3:0
    Discount rate 4:.1
    Discount rate :.1
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    【讨论】:

    • 哦!只是我犯了一个愚蠢的错误。我忘了写; dbms_output.put_line 语句中的符号。谢谢你的帮助.. :))
    • @ankitaP:所以,基本上,您在问题中输入的代码不是导致错误的代码?
    • 按“退出”按钮后,从“开始”到“结束”的代码在逻辑上是正确的,但我没有提及;当我在我的 SQL *Plus 中做的时候就在那里,所以错误就像我写的一样。但我确实提到了;当我在stackoverflow中询问时。我太傻了:/
    猜你喜欢
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    • 2014-09-18
    • 2012-10-26
    • 1970-01-01
    相关资源
    最近更新 更多