【发布时间】: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 新手。
【问题讨论】: