我写了以下包和包体:
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 新手。