MCQ Bank
Which of the following is TRUE while using PL/SQL Exit Loop?
- A) Variables in the loop are incremented.
- B) When you are ready to exit the loop, you should use the EXIT WHEN statement.
- C) All of the mentioned
- D) The loop body should be initialized with a variable
A/An _______ loop in PL/SQL ensures that at least one statement is executed before the loop terminates.
- A) While
- B) Exit
- C) Cursor For
- D) For
BEGIN FOR l_index IN 1 .. 10 LOOP CONTINUE WHEN MOD (l_index, 2) = 0; DBMS_OUTPUT.PUT_LINE ('Loop index = ' || TO_CHAR (l_index)); END LOOP; END; / Output for this piece of code :
- A) Loop index = 1
- B) Loop index = 5 Loop index = 7 Loop index = 9
- C) Loop index = 1 Loop index = 3
- D) Loop index = 1 Loop index = 3 Loop index = 5 Loop index = 7 Loop index = 9
Loop without exit condition is a/an _____________ loop.
- A) Finite
- B) While
- C) For
- D) Infinite
By using PL/SQL _______, you can repeatedly execute one or more statements over and over again.
- A) Loops
- B) Cursor
- C) Case
- D) Variables
DECLARE no NUMBER := 0; BEGIN FOR no IN 1 .. 5 LOOP DBMS_OUTPUT.PUT_LINE('Iteration : ' || no); CONTINUE WHEN no = 4 DBMS_OUTPUT.PUT_LINE('CONTINUE WHEN EXECUTE Iteration : ' || no); END LOOP; END; / Output for this piece of code :
- A) Iteration # 1 Iteration # 2 Iteration # 3 CONTINUE WHEN EXECUTE Iteration: 4
- B) Iteration # 1 Iteration # 3 CONTINUE WHEN EXECUTE Iteration: 4 Iteration # 5
- C) Iteration # 1 Iteration # 2 Iteration # 3 CONTINUE WHEN EXECUTE Iteration: 4 Iteration # 5
- D) Iteration # 1 Iteration # 2 Iteration # 3
You can also use CONTINUE to terminate an ___________loop and continue immediately on to the next iteration of an outer loop’s body.
- A) Outer
- B) Nested
- C) Simple
- D) Inner
BEGIN WHILE lv_cnt_num <= 5 LOOP DBMS_OUTPUT.PUT_LINE(lv_cnt_num); lv_cnt_num := lv_cnt_num + 1; END LOOP; END; According to the code fragment above, how many times does the loop iterate?
- A) 4
- B) 6
- C) 3
- D) 5
1. BEGIN 2. FOR loop_index IN 1..5 3. LOOP 4. dbms_output.put_line(loop_index); 5. dbms_output.put_line('Before the Continue statement'); 6. CONTINUE; 7. dbms_output.put_line('After the Continue statement'); 8. END LOOP loop_index; 9. dbms_output.put_line('Loop has been terminated'); 10. END; 11. /
- A) 1 Before the Continue statement 2 Before the Continue statement 3 Before the Continue statement
- B) 1 Before the Continue statement 2 Before the Continue statement 3 Before the Continue statement 4 Before the Continue statement 5 Before the Continue statement Loop has been terminated
- C) 4 Before the Continue statement 5 Before the Continue statement Loop has been terminated
- D) 1 Before the Continue statement 2 Before the Continue statement 3 Before the Continue statement 4 Before the Continue statement
Which of the following is TRUE while using PL/SQL FOR Loop?
- A) The counter variable is implicitly declared in the declaration section, so you do not need to declare it explicitly.
- B) It is not necessary to explicitly increment the counter variable since it is incremented by 1
- C) FOR loops can use EXIT WHEN and EXIT statements, but it isn't often used.
- D) All of the mentioned
PL/SQL Loops are also known as
- A) Indentation Control Statements
- B) Indentation Case Statements
- C) Iterative Case Statements
- D) Iterative Control Statements
Sequence of statements are executed in each iteration.___________ loop exit when condition is evaluated to false.
- A) While
- B) For
- C) Nested
- D) Do while
A ______ statement allows us to execute a statement or group of statements multiple times.
- A) loop
- B) condition
- C) array
- D) procedure
When you want to execute a series of statements repeatedly, you use the PL/SQL ____ loop.
- A) While
- B) Cursor For
- C) Cursor
- D) For
What is the syntax of PL/SQL Loop?
- A) LOOP Sequence of statements; END LOOP;
- B) END LOOP; LOOP Sequence of statements;
- C) END LOOP; Sequence of statements; LOOP
- D) LOOP END LOOP; Sequence of statements;
Which structure executes a sequence of statements repeatedly as long as a condition holds true?
- A) Selection structure
- B) Sequence structure
- C) Iteration structure
- D) None of the above
DECLARE x NUMBER := 0; BEGIN LOOP -- After CONTINUE statement, control resumes here DBMS_OUTPUT.PUT_LINE ('Inside loop: x = ' || TO_CHAR(x)); x := x + 1; IF x < 3 THEN CONTINUE; END IF; DBMS_OUTPUT.PUT_LINE ('Inside loop, after CONTINUE: x = ' || TO_CHAR(x)); EXIT WHEN x = 5; END LOOP; DBMS_OUTPUT.PUT_LINE (' After loop: x = ' || TO_CHAR(x)); END; / Output for this piece of code :
- A) Inside loop: x = 0 Inside loop: x = 1 Inside loop: x = 2 Inside loop, after CONTINUE: x = 3 Inside loop: x = 3 Inside loop, after CONTINUE: x = 4
- B) Inside loop: x = 0 Inside loop: x = 1 Inside loop: x = 2 Inside loop, after CONTINUE: x = 3
- C) Inside loop: x = 0 Inside loop: x = 1 Inside loop: x = 2 Inside loop, after CONTINUE: x = 3 Inside loop: x = 3 Inside loop, after CONTINUE: x = 4 Inside loop: x = 4 Inside loop, after CONTINUE: x = 5 After loop: x = 5
- D) Inside loop: x = 0 Inside loop: x = 1 Inside loop: x = 2 Inside loop, after CONTINUE: x = 3 Inside loop: x = 3 Inside loop, after CONTINUE: x = 4
Which of the following code fragments would not raise an error?
- A) BEGIN FOR i IN 1..10 LOOP DBMS_OUTPUT.PUT_LINE(i); END LOOP; END;
- B) BEGIN FOR i IN 1..10 LOOP DBMS_OUTPUT.PUT_LINE(c) END LOOP END;
- C) BEGIN FOR i IN 1..10 LOOP DBMS_OUTPUT.PUT_LINE END LOOP END;
- D) BEGIN FOR i IN 1..10 DBMS_OUTPUT.PUT_LINE(i); END LOOP; END;
How many times does a WHILE Loop run?
- A) One or many
- B) Until the condition becomes FALSE
- C) Until the condition becomes TRUE
- D) Zero or one
Does PL/SQL allows using one loop inside another loop.
- A) Can be yes or no
- B) No
- C) Cannot say
- D) Yes