1Z0-149 practice question 11 of 15

SERVEROUTPUT is enabled. Which code block will display the values from 1 to 10 in descending order?

Full set: 65 questions
Answer options
A: exam question
B: exam question Correct answer
C: exam question
D: exam question Correct answer
Correct Answer:
B. https://kxbjsyuhceggsyvxdkof.supabase.co/storage/v1/object/public/file-images/1Z0-149/page_40_img_2.jpg; D. https://kxbjsyuhceggsyvxdkof.supabase.co/storage/v1/object/public/file-images/1Z0-149/page_41_img_1.jpg
Explanation

Both code blocks will correctly display the values from 10 down to 1. Option B uses a FOR loop with the REVERSE keyword, which is the most concise and idiomatic PL/SQL construct for iterating backwards over a fixed integer range. Option D uses a WHILE loop, which also achieves the correct result by explicitly initializing a counter to 10, checking its value in each iteration, and decrementing it. Both are functionally correct and produce the required output.

Why Incorrect

A: The standard FOR i IN 1..10 loop iterates in ascending order, printing numbers from 1 to 10. C: A FOR loop with a range like 10..1 will not execute any iterations because the lower bound is greater than the upper bound.

References

1. Oracle Database PL/SQL Language Reference, 21c, Chapter 4, "PL/SQL Control Statements". Section: "FOR LOOP Statement". It states, "The REVERSE keyword causes the loop to be executed in reverse, from the upper bound to the lower bound."

2. Oracle Database PL/SQL Language Reference, 21c, Chapter 4, "PL/SQL Control Statements". Section: "WHILE LOOP Statement". This section describes the syntax and provides examples of using a WHILE loop with a counter, similar to the implementation in option D.

Scroll to Top