Which statement is true about the blocks of code?

View the Exhibit and examine the blocks of code that you plan to execute.

Which statement is true about the blocks of code?

View the Exhibit and examine the blocks of code that you plan to execute.

Which statement is true about the blocks of code?

A.
All the blocks execute successfully and the anonymous block displays
1
2
3
cant: 45
45
cnt: 45

B.
All the blocks execute successfully and the anonymous block displays
1
2
3
cut: 0
45
cart: 1

C.
The anonymous block gives an error because the function invocation in line 2 is not valid.

D.
The procedure creation gives an error because the function invocation in line 1 is not valid.

Explanation:



Leave a Reply 8

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


samkelo siyabonga ngubo

samkelo siyabonga ngubo

A

samkelo siyabonga ngubo

samkelo siyabonga ngubo

B is an answer check it out :
DECLARE
cnt pls_integer := 0;
FUNCTION dflt RETURN pls_integer IS
BEGIN
cnt := cnt + 1;
RETURN 45;
END dflt;
— Default is expression
PROCEDURE p(i IN pls_integer DEFAULT dflt()) IS
BEGIN
DBMS_Output.Put_Line(i);
END p;
BEGIN
FOR j IN 1..5 LOOP
p(j); — Actual parameter is provided
END loop;
DBMS_Output.Put_Line(‘cnt: ‘||cnt);
p(); — Actual parameter is not provided
DBMS_Output.Put_Line(‘cnt: ‘||cnt);
END;

Result:
1
2
3
4
5
cnt: 0
45
cnt: 1

http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/subprograms.htm#i6821

pavlov.leo

pavlov.leo

Your code different from code in the Exhibit:
you have one anonimous block with with variable “cnt” and nested function that increvent that value.
In the Exhibit there are diferent blocks with its own variables “cnt” not visible to each other.

Just try to execute the exact code from the Exhibit (use “/” after each block in SQLPlus).
Answer is “A”

Piero

Piero

A

— Q31

create or replace function dflt RETURN NUMBER IS
cnt NUMBER := 0;
BEGIN
CNT := CNT + 1;
RETURN 45;
END DFLT;

CREATE OR REPLACE PROCEDURE P(I IN NUMBER DEFAULT DFLT()) IS
BEGIN
DBMS_OUTPUT.PUT_LINE(I);
END P;

DECLARE
CNT NUMBER := DFLT();
BEGIN
FOR J IN 1..3 LOOP
P(J);
END LOOP;
DBMS_OUTPUT.PUT_LINE (‘CNT ‘ || CNT);
P();
DBMS_OUTPUT.PUT_LINE(‘CNT ‘ || CNT);
END;

1
2
3
CNT 45
45
CNT 45

samkelo siyabonga ngubo

samkelo siyabonga ngubo

the Answer is A I made mistake