我编写了以下Package and Package主体:
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准备认证考试的新手。
答案 0 :(得分: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>