What is the result?

Examine this package
CREATE OR REPLACE PACKAGE discounts
IS
g_id NUMBER:=7839
discount_rate NUMBER:=0.00;
PROCEDURE display_price(p_price NUMBER);
END discount;
/
CREATE OR REPLACE PACKAGE BODY discounts
IS
PROCEDURE display_price (p_price NUMBERI)
IS
BEGIN
DBMS_OUTPUT.PUT LINE ( ‘Discounted ‘||
TO_CHAR(p_price*NVL(discount_rate,1)));
END discount;
BEGIN
Discount_rate=0.10;
END discounts;
/
The SOL*Plus SERVEROUTPUT setting is turned on in your session. You execute the procedure DISPLAY_PRICE from SOL*Plus with the command EXECUTE discount.display_price(100);
What is the result?

Examine this package
CREATE OR REPLACE PACKAGE discounts
IS
g_id NUMBER:=7839
discount_rate NUMBER:=0.00;
PROCEDURE display_price(p_price NUMBER);
END discount;
/
CREATE OR REPLACE PACKAGE BODY discounts
IS
PROCEDURE display_price (p_price NUMBERI)
IS
BEGIN
DBMS_OUTPUT.PUT LINE ( ‘Discounted ‘||
TO_CHAR(p_price*NVL(discount_rate,1)));
END discount;
BEGIN
Discount_rate=0.10;
END discounts;
/
The SOL*Plus SERVEROUTPUT setting is turned on in your session. You execute the procedure DISPLAY_PRICE from SOL*Plus with the command EXECUTE discount.display_price(100);
What is the result?

A.
Discounted 10

B.
Discounted 100

C.
Discounted 0.00

D.
Discounted NULL

E.
Discounted 0.10

Explanation:
The discounts package contains a one-time-only procedure which is executed when the package is first referenced and sets the public variable discount_rate = .10. The value of 100 is passed to the p_price parameter and this is multipled by the discount_rate resulting in a value of ‘Discounted 10’ is displayed by the DBMS_OUTPUT.PUT_LINE.
Incorrect Answers
B, C, D & E are incorrect



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Shailesh Jori

Shailesh Jori

The variable discount_rate will be initialized to 0.10 only after first call to Discount procedure.So when we execute Discount procedure for the first time, it should return 0 (0.00*100) and after that for each and everty call ,it should return 10 (0.1*100).

surprise

surprise

>The variable discount_rate will be initialized to 0.10 only after first >call to Discount procedure

You are wrong. It is initialized before first call.

Shahidul

Shahidul

I have created the package myself and tested. The result is
“Discounted 10”

Thanks.