Week9 - Introduction to PL/SQL, Control Statements / Explore

The questions can come in any order, so make sure you are selecting right option for all questions.

1. Which of the following is true about comments in PL/SQL?

(d) All of these

2. What will be the output of the following code snippet?

DECLARE
a number (2) := 21;
b number (2) := 10;
BEGIN

IF ( a <= b ) THEN
dbms_output.put_line(a);
END IF;

IF ( b >= a ) THEN
dbms_output.put_line(a);
END IF;

IF ( a <> b ) THEN
dbms_output.put_line(b);

END IF;

END;

(c) 10

3. What is the output of the following code?

DECLARE
grade char(1) := 'B';
BEGIN
case
when grade = 'A' then dbms_output.put_line('Excellent');
when grade = 'B' then dbms_output.put_line('Very good');
when grade = 'C' then dbms_output.put_line('Well done');
when grade = 'D' then dbms_output.put_line('You passed');
when grade = 'F' then dbms_output.put_line('Better try again');
else dbms_output.put_line('No such grade');
end case;
END;

(c) Very good

4. Consider the following code snippet: what will be the output?

DECLARE
a number(2) ;
BEGIN
FOR a IN REVERSE 10 .. 20 LOOP
END LOOP;
dbms_output.put_line(a);
END;

(b) 10

5. The only required keywords of a PL/SQL block are the ____ keywords.

(c) BEGIN & END

6. The ____ section of a PL/SQL block contains code that creates variables, cursors, and types.

(a) DECLARE

7. ____ are used to change the values of variables.

(b) Assignment Statements

8. ____ are named memory areas that hold values to allow the retrieval and manipulation of values in a program.

(d) Variables

9. Which of the following lines of code is syntactically correct?

(d)
DECLARE
order NUMBER(3);
departure DATE;
BEGIN
—- executable statements —
END;

10. Which of the following initializes the variable order?

(d)
DECLARE
order NUMBER(2) := 0;
departure DATE;
BEGIN
—- executable statements —
END;

11. Which of the following PL/SQL blocks requires the variable to always contain a particular value within the block?

(c)
DECLARE
order CONSTANT NUMBER(2,2) := .02;
departure DATE;
BEGIN
—- executable statements —
END;

12. DECLARE
order NUMBER(2) := 4;
total_amt NUMBER(2);
BEGIN
total_amt := order * 8;
END;

According to the statement block above, what value is stored in the variable total_amt?

(d) 32

13. Which of the following statement blocks correctly uses a scalar variable in an assignment statement?

(b)
DECLARE
order NUMBER(2) := 4;
total_amt NUMBER(2);
BEGIN
total_amt := 12 * order;
END;

14. The statements that are used to control the flow of logic processing in your programs are commonly referred to as ____.

(b) control structures

15. Which of the following statements is correct?

(d)
IF order > 5 THEN
prize := ‘yes’;
END IF;

16. Which of the following code fragments would not raise an error?

(c)
IF rec_order.state = ’VA’ THEN
lv_tax_num := rec_order.sub * .06;
ELSIF rec_order.state = ’ME’ THEN
lv_tax_num := rec_order.sub * .05;
ELSE
lv_tax_num := rec_order.sub * .04;
END IF;

17. Which of the following code fragments would not raise an error?

(b)
IF rec.state = ’VA’ OR rec.state = ’PA’ THEN
a := b * .06;
ELSE
a := b * .04;
END IF;

18. Which of the following does not use a selector, but individually evaluates conditions that are placed in WHEN clauses?

(b) Searched CASE

19. Which of the following evaluates conditions and returns a value in an assignment statement?

(c) CASE expression

20. Which of the following statements is true?

(c) The WHEN clause of a CASE expression does not end with a semicolon.

21. The ____ uses the LOOP and END LOOP markers to begin and end the loop code.

(a) basic loop

22. Which of the following code fragments would not raise an error?

(d)
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE( lv_cnt_num );
EXIT WHEN lv_cnt_num >= 5;
lv_cnt_num := lv_cnt_num + 1;
END LOOP;
END;

23. Which of the following clauses ensures that a basic loop runs at least once?

(a) EXIT WHEN

24.
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(lv_cnt_num);
lv_cnt_num := lv_cnt_num + 1;
EXIT WHEN lv_cnt_num >= 5;
END LOOP;
END;

Which of the statements in the code fragment above ensures that the loop executes at least once?

(c)EXIT WHEN lv_cnt_num >= 5;

25. What is the output of the following code?

DECLARE
grade char(1) := 'B';
BEGIN
case
when grade = 'A' then dbms_output.put_line('Excellent');
when grade = 'B' then dbms_output.put_line('Very good');
when grade = 'C' then dbms_output.put_line('Well done');
when grade = 'D' then dbms_output.put_line('You passed');
when grade = 'F' then dbms_output.put_line('Better try again');
else dbms_output.put_line('No such grade');
end case;
END;

(c) Very good

26. What will be the output of the following code snippet?

DECLARE
a number (2) := 21;
b number (2) := 10;
BEGIN

IF ( a <= b ) THEN
dbms_output.put_line(a);
END IF;

IF ( b >= a ) THEN
dbms_output.put_line(a);
END IF;

IF ( a <> b ) THEN
dbms_output.put_line(b);

END IF;

END;

(c) 10

27. Consider the following code snippet: what will be the output?

set serveroutput on;
DECLARE
a number(2);
b number(2);
BEGIN
FOR a IN REVERSE 10..20 LOOP
b:=a;
END LOOP;
dbms_output.put_line(b);
END; /

(b) 10

28. Which of the following is true about comments in PL/SQL?

(d) All of these

29. Which of the following does not use a selector, but individually evaluates conditions that are placed in WHEN clauses?

(b) Searched CASE

30. Which of the following code fragments would not raise an error?

(d)
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE( lv_cnt_num );
EXIT WHEN lv_cnt_num >= 5;
lv_cnt_num := lv_cnt_num + 1;
END LOOP;
END;

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.