Reputation: 85
I wrote the following Package and Package body:
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;
/
It is written that "The value of discount_rate is set to 0.10 when the package is invoked for the first time in a session". I am not getting this point exactly that's why I checked the value each time of discount rate. I typed the following to invoke:
SQL> execute discounts.display_price(1000);
Discount rate 3:0
Discount rate 4:.1
Discount rate 1:.1
Discounted 100
Discount rate 2:.1
Then again I invoked the variable:
begin
dbms_output.put_line('Discount rate :'||discounts.discount_rate);
end;
SQL> /
Discount rate :.1
Then I typed "exit" to close the SQL *PLUS. Again I opened SQL *PLUS and typed the same code:
begin
dbms_output.put_line('Discount rate :'||discounts.discount_rate);
end;
I thought it will not initialize the variable but I got the error:
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.
What is the mistake ? I am new to PL/SQL preparing for certification exam.
Upvotes: 1
Views: 17245
Reputation: 65054
Sorry, I could not reproduce the error you showed:
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>
Upvotes: 1