Test: Section 4 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 4 Quiz
(Answer all questions in this section)
1. What clause will leave the outer loop at Point A?
DECLARE
i INTEGER := 0;
BEGIN
<< i_loop >>
WHILE i <= 10 LOOP
i := i+1;
<< j_loop >>
FOR j IN 1..5 LOOP
_______ WHEN i = j*2; -- Point A
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
Mark for Review
(1) Points
EXIT j_loop
EXIT outerloop
EXIT i_loop (*)
EXIT << outerloop>>
Correct Correct
2. Look at the following code:
DECLARE
v_blue NUMBER(3) := 0;
v_red NUMBER(3) := 0;
BEGIN
<< blue >> LOOP
v_blue := v_blue + 1;
EXIT WHEN v_blue > 10;
<< red >> LOOP
v_red := v_red + 1;
EXIT WHEN v_red > 10;
-- Line A
END LOOP red;
END LOOP blue;
END;
What should you code at Line A to exit from the outer loop?
Mark for Review
(1) Points
EXIT blue; (*)
EXIT red;
EXIT << blue>>
EXIT;
Correct Correct
3. Examine the following code:
DECLARE
v_outer_count NUMBER := 1;
v_inner_count NUMBER := 1;
BEGIN
LOOP
LOOP
v_inner_count := v_inner_count + 1;
EXIT WHEN v_inner_count > 5; -- Line A
END LOOP;
v_outer_count := v_outer_count + 1;
EXIT WHEN v_outer_count > 3;
END LOOP;
END;
What happens at Line A when the value of V_INNER_COUNT equals 6?
Mark for Review
(1) Points
Both loops are exited and the block's execution is terminated.
The outer loop is exited but the inner loop continues execution.
An error condition is returned.
The inner loop is exited but the outer loop continues execution. (*)
Correct Correct
4. What will be displayed when this block is executed?
DECLARE
v_count NUMBER := 10;
v_result NUMBER;
BEGIN
LOOP
v_count := v_count - 1;
EXIT WHEN v_count < 5;
v_result := v_count * 2;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_result);
END;
Mark for Review
(1) Points
NULL
10 (*)
12
Correct Correct
5. A PL/SQL block contains the following code:
v_counter := 1;
LOOP
EXIT WHEN v_counter=5;
END LOOP;
v_counter := v_counter + 1;
What is the value of V_COUNTER after the loop is finished?
Mark for Review
(1) Points
This is an infinite loop; the loop will never finish. (*)
Correct Correct
Page 1 of 3 Next Summary
Test: Section 4 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 4 Quiz
(Answer all questions in this section)
6. What are the three kinds of loops in PL/SQL? Mark for Review
(1) Points
FOR, WHILE, basic (*)
IF, CASE, LOOP
ascending, descending, unordered
infinite, finite, recursive
Correct Correct
7. Look at the following (badly written) code:
age := 5; IF age<30 THEN mature := 'adult';
ELSIF age<22 THEN mature := 'teenager';
ELSIF age<13 THEN mature := 'child';
END IF;
DBMS_OUTPUT.PUT_LINE(mature);
What will be displayed when this code is executed?
Mark for Review
(1) Points
adult (*)
teenager
child
adultteenagerchild
Correct Correct
8. What is wrong with the following trivial IF statement:
IF (v_job='President')
THEN v_salary := 10000;
Mark for Review
(1) Points
ELSE is missing
IF and THEN must be on the same line: IF (v_job='President') THEN ...
The condition should be coded: IF (v_job := 'President')
END IF; is missing (*)
Correct Correct
9. What will be displayed when this block is executed? DECLARE
v_birthdate DATE;
BEGIN
IF v_birthdate < '01-Jan-2000'
THEN
DBMS_OUTPUT.PUT_LINE(' Born in the 20th century ');
ELSE
DBMS_OUTPUT.PUT_LINE(' Born in the 21st century ');
END IF;
END;
Mark for Review
(1) Points
Exception raised because no date given
Born in the 20th century
Born in the 21st century (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
10. You want to assign a value to v_result which depends on the value
of v_grade: if v_grade = 'A' set v_result to 'Very Good' and so on.
DECLARE
v_grade CHAR(1);
v_result VARCHAR2(10);
BEGIN
v_result :=
CASE v_grade
The next line should be
Mark for Review
(1) Points
WHEN v_grade = 'A' THEN 'Very Good'
WHEN 'A' THEN v_result := 'Very Good';
WHEN 'A' THEN = 'Very Good';
WHEN 'A' THEN 'Very Good' (*)
Correct Correct
Previous Page 2 of 3 Next Summary
Test: Section 4 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 4 Quiz
(Answer all questions in this section)
11. How must you end a CASE expression? Mark for Review
(1) Points
ENDCASE;
ENDIF;
END; (*)
END CASE;
Correct Correct
12. What will be displayed when the following block is executed?
DECLARE
v_age1 NUMBER(3);
v_age2 NUMBER(3);
v_message VARCHAR2(20);
BEGIN
CASE
WHEN v_age1 = v_age2 THEN v_message := 'Equal';
WHEN v_age1 <> v_age2 THEN v_message := 'Unequal';
ELSE v_message := 'Undefined';
END CASE;
DBMS_OUTPUT.PUT_LINE(v_message);
END;
Mark for Review
(1) Points
Nothing will be displayed because V_MESSAGE is set to NULL.
Undefined (*)
Equal
Unequal
Correct Correct
13. Examine the following code:
DECLARE
v_bool BOOLEAN := FALSE;
v_counter NUMBER(4) := 0;
BEGIN
... Line A
�
END;
Which of the following is NOT valid at line A?
Mark for Review
(1) Points
WHILE NOT v_boolean LOOP
WHILE v_counter IN 1..5 LOOP (*)
WHILE v_counter > 8 LOOP
WHILE v_boolean AND v_counter < 6 LOOP
Incorrect Incorrect. Refer to Section 4 Lesson 4.
14. Which statement best describes when a FOR loop should be used?
Mark for Review
(1) Points
When the number of iterations is known (*)
When testing the value in a Boolean variable
When the controlling condition must be evaluated at the start of each
iteration
Correct Correct
15. Look at the following code fragment:
i := 2;
WHILE i < 3 LOOP
i := 4;
DBMS_OUTPUT.PUT_LINE('The counter is: ' || i);
END LOOP;
How many lines of output will be displayed?
Mark for Review
(1) Points
One line (*)
Two lines
No lines
The block will fail because you cannot use DBMS_OUTPUT.PUT_LINE inside a
loop.
Correct Correct
Previous Page 3 of 3 Summary