Oracle Quiz Answers. Oracle Quiz Questions An asterisk (*) indicates a correct answer.
marți, 12 martie 2013
Section 2 Lesson 6: Nested Blocks and Variable Scope
Nested Blocks and Variable Scope
Section 1
1. A variable is global to an outer block and local to the inner block. True or False? (1) Points
True
False (*)
2. Examine the following code. What is the scope of variable v_myvar?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 6;
DECLARE
v_hervar NUMBER;
BEGIN
v_hervar := 4;
END;
END;
(1) Points
Only the outer block
Both the inner and the outer block (*)
Only the inner block
Neither block
3. What values will be displayed when the following code is executed?
DECLARE
v_mynum NUMBER;
BEGIN
v_mynum := 7;
DECLARE
v_mynum NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_mynum);
v_mynum := 3;
END;
DBMS_OUTPUT.PUT_LINE(v_mynum);
END;
(1) Points
3,3
3,7
Null, 7 (*)
Null, 3
4. Examine the following code. Line A causes an exception. What will be displayed when the block is executed?
DECLARE
x NUMBER := 10;
y NUMBER;
BEGIN
x := 15;
y := 'Happy'; -- Line A
x := 20;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
10
20
15 (*)
Nothing is displayed
5. For the anonymous block below, what is the correct reference to the father's date of birth in the inner block?
<<outer>>
DECLARE
v_father_name VARCHAR2(20):='Patrick';
v_date_of_birth DATE:='20-Apr-1972';
BEGIN
DECLARE
v_child_name VARCHAR2(20):='Mike';
v_date_of_birth DATE:='12-Dec-2002';
...
(1) Points
v_date_of_birth.outer
<<outer>>v_date_of_birth
<<outer.v_date_of_birth>>
outer.v_date_of_birth (*)
6. An inner block is nested within an outer block. An exception occurs within the inner block, but the inner block does not have an EXCEPTION section. What happens? (1) Points
The exception is propagated to the outer block and the remaining executable statements in the outer block are skipped. (*)
The exception is propagated to the outer block and the remaining executable statements in the outer block are executed.
Oracle automatically tries to re-execute the inner block.
The outer block is bypassed and the exception is always propagated to the calling environment.
7. What is wrong with this code?
DECLARE
v_a NUMBER;
BEGIN
v_a := 27;
<<inner_block>>
BEGIN
v_a := 15;
END;
(1) Points
The outer block has no label.
Variable v_a is out of scope within the inner block and therefore cannot be referenced.
The inner block has no END; statement. (*)
Nothing is wrong, the code will execute successfully.
8. What happens when an exception occurs in the executable section of a PL/SQL block? (1) Points
Oracle keeps trying to re-execute the statement which caused the exception.
The remaining statements in the executable section are not executed. Instead, Oracle looks for an EXCEPTION section in the block. (*)
The remaining statements in the executable section of the block are executed.
The exception is always propagated to the calling environment.
9. Examine the following nested blocks. Line B causes an exception. What will be displayed when this code is executed?
DECLARE
var_1 NUMBER;
BEGIN
var_1 := 4;
DECLARE
var_2 NUMBER;
BEGIN
var_2 := 'Unhappy'; -- Line B
var_1 := 8;
END;
var_1 := 12;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_1);
END;
(1) Points
Unhappy
12
8
4 (*)
10. Examine the following code. At Line A, we want to assign a value of 25 to the outer block's variable (V1). What must we do?
DECLARE
v_myvar NUMBER; -- This is V1
BEGIN
DECLARE
v_myvar NUMBER := 8;
BEGIN
-- Line A
END;
END;
(1) Points
At Line A, code:
v_myvar := 25;
Label both blocks and at line A, code:
v_myvar := 25;
It cannot be done because the outer block's v_myvar is out of scope at Line A.
Label the outer block and (at Line A) dot-prefix v_myvar with the block label. (*)
It cannot be done because the outer block's v_myvar is in scope but not visible at Line A.
Abonați-vă la:
Postare comentarii (Atom)
Niciun comentariu:
Trimiteți un comentariu