Section 4
Examine
the following code::
DECLARE
v_count NUMBER :=
0;
v_string
VARCHAR2(20);
BEGIN
LOOP
v_string :=
v_string || 'x';
IF
LENGTH(v_string) > 10 THEN
END IF;
v_count :=
v_count + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_count);
END;
What will be displayed when this block is executed?
xxxxxxxxxxx
10 (*)
9
11
Which kind of loop is this?
i := 10;
LOOP
i := i + 1;
EXIT WHEN i >
30;
END LOOP;
A FOR
loop
A
nested loop
A WHILE
loop
A basic
loop (*)
An
infinite loop
The EXIT statement can be
located anywhere inside a basic loop. True or False?
True
(*)
False
Look at this code fragment:
FOR i IN 1 .. 3 LOOP
i := 4;
DBMS_OUTPUT.PUT_LINE('The
counter is: ' || i);
END LOOP;
How many lines of output will be displayed?
Four
One
The
block will fail because you cannot change the value of i inside the loop. (*)
Three
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?
Two
lines
No
lines
One
line (*)
The
block will fail because you cannot use DBMS_OUTPUT.PUT_LINE inside a loop.
In a WHILE loop, the controlling
condition is checked at the start of each iteration. True or False?
True
(*)
False
What is the correct form of a
compound IF statement?
IF
condition
THEN statement1
ELSE statement 2;
IF
condition THEN statement1;
ELSE statement2;
END IF;
(*)
IF
condition
THEN statement1
ELSE statement 2;
END IF;
IF
condition;
THEN statement1;
ELSE statement2;
END IF;
Name three types of control
structures in PL/SQL. (Choose three)
IF
statements (*)
LOOP
statements (*)
SELECT
statements
EXCEPTIONS
CASE
statements (*)
Examine the following code:
DECLARE
a VARCHAR2(6) :=
NULL;
b VARCHAR2(6) :=
NULL;
BEGIN
IF a = b THEN
DBMS_OUTPUT.PUT_LINE('EQUAL');
ELSIF a != b THEN
DBMS_OUTPUT.PUT_LINE('UNEQUAL');
ELSE
DBMS_OUTPUT.PUT_LINE('OTHER');
END IF;
END;
Which word will be displayed?
OTHER
(*)
Nothing
will be displayed
EQUAL
UNEQUAL
What will be displayed when the
following block is executed?
DECLARE
v_age NUMBER(3);
v_gender VARCHAR2(6)
:= 'Female';
v_status
VARCHAR2(20);
BEGIN
CASE
WHEN v_age >=
18 AND v_gender = 'Male' THEN v_status := 'Adult Male';
WHEN v_age >=
18 AND v_gender = 'Female' THEN v_status := 'Adult Female';
WHEN v_age < 18
AND v_gender = 'Male' THEN v_status := 'Junior Male';
WHEN v_age < 18
AND v_gender = 'Female' THEN v_status := 'Junior Female';
ELSE v_status :=
'Other Value';
END CASE;
DBMS_OUTPUT.PUT_LINE(v_status);
END;
Nothing
will be displayed because V_STATUS is set to NULL.
Other
Value (*)
Adult
Male
Junior
Female
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;
Unequal
Equal
Undefined
(*)
Nothing
will be displayed because V_MESSAGE is set to NULL.
What value will v_answer contain
after the following code is executed?
DECLARE
v_age NUMBER:= 18;
v_answer
VARCHAR2(10);
BEGIN
v_answer :=
CASE
WHEN v_age
< 25 THEN 'Young'
WHEN v_age =
18 THEN 'Exactly 18'
ELSE 'Older'
END;
Young
(*)
Null
Older
Exactly
18
Examine the following code:
BEGIN
FOR i IN 1..5 LOOP
FOR j IN 1..8 LOOP
EXIT WHEN j = 7;
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
How many lines of output will be displayed when this code is
executed?
35
40
30 (*)
6
Which one of these statements
about using nested loops is true?
The
outer loop must be labeled if you want to exit the outer loop from within the
inner loop. (*)
All the
loops must be labeled.
Both
loops can have the same label.
The
outer loop must be labeled, but the inner loop need not be labeled.
In the following code fragment,
you want to exit from the outer loop at Line A if v_number = 6. Which statement
would you write on Line A?
<< big_loop >>
WHILE condition_1 LOOP
<<
small_loop >>
FOR i IN 1..10
LOOP
DBMS_OUTPUT.PUT_LINE(i);
-- Line A
END LOOP;
END LOOP;
EXIT
outer_loop WHEN v_number = 6;
IF
v_number = 6 THEN EXIT;
EXIT
big_loop WHEN v_number = 6; (*)
EXIT
small_loop WHEN v_number = 6;
No comments:
Post a Comment