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
123
cant: 45
45
cnt: 45
B.
All the blocks execute successfully and the anonymous block displays
123
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.
A
A
a
A
C, D
Functions cannot be inviked in DEFAULT or CHECK clause.
create or replace function dflt RETURN NUMBER IS
cnt NUMBER := 0;
BEGIN
cnt := cnt + 1;
RETURN 45;
end;
create or replace procedure p(i in NUMBER DEFAULT dflt() )
BEGIN
dbms_output.put_line(i);
END p;
Function created.
Warning: compiled but with compilation errors
END;
Error at line 12
ORA-00900: invalid SQL statement
it seems you missing “IS” before “BEGIN”
Just tried it and the result is:
PL/SQL procedure successfully completed.
1
2
3
cnt: 45
45
cnt: 45
So correct answer is A
A is the correct ans, i have tested this.
A
p( ) is 45 because it has the default value of dflt( )
B is the correct Answer actually!
Please see the example below:
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/subprograms.htm
Answer is A.
In your example CNT variable is NOT in function DFLT.
A
A
create or replace function dflt RETURN NUMBER IS
cnt NUMBER := 0;
BEGIN
cnt := cnt + 1;
RETURN 45;
end;
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;
Verified : Answer A is correct
why “cant” ?
A
A
Function created.
Procedure created.
1
2
3
cnt: 45
45
cnt: 45
PL/SQL procedure successfully completed.
A