Header Ads Widget

Module 05: Writing Control Structures

Writing Control Structures


01. Evaluate this PL/SQL block.

BEGIN

FOR i IN 1..10 LOOP

IF I=4 OR I=6 THEN

null;

ELSE

INSERT INTO test(result)

VALUES (I) ;

END IF;

COMMIT;

END LOOP;

ROLL BACK;

END.

How many values will be inserted into the TEST table?

a. 0

b. 4

c. 6

d. 8

e. 10

Answer: d

02. Evaluate this IF statement.

IF v_value > 100 THEN

v_new_value := 2 * v_value;

ELSIF v_value > 200 THEN

V_new_value := 3 * v_value;

ELSIF v_value > 300 THEN

V_new_value := 4 * v_value;

ELSE

v_new_value := 5 * v_value;

END IF;

What would be assigned to v_new_value if v_value = 250?

a. 250

b. 500

c. 750

d. 1000

Answer: b

03. If left out, which of the following would cause an infinite loop to occur in a simple loop?

a. LOOP.

b. END LOOP.

c. IF-THEN.

d. EXIT.

Answer: d

04. Which of the following statements are true about WHILE loops?

a. Explicit exit statements are required in while loops.

b. Counter variables are required in while loops.

c. An if-then statement is needed to signal when a while loop should end.

d. All exit conditions for while loops are handled in the exit when clause.

Answer: b

05. Evalu`ate this PL/SQL Block:

DECLARE

v_lower NUMBER := 2;

v_upper NUMBER := 100;

v_count NUMBER := 1;

BEGIN

For I in v_lower .. v_lower loop

Insert into test (result)

Values (v_count);

 v_count := v_count + 1;

END LOOP;

END;

How many times will the executable statements inside the FOR LOOP execute? 

a. 0

b. 1

c. 98

d. 100

Answer: b

06. In a PL/SQL IF-THEN-ELSE statement, which value will cause the conditional statement to execute?

a. NULL .

b. TRUE.

c. FALSE.

Answer: b

07. What causes a PL/SQL WHILE loop to terminate?

a. Control is passed to the EXIT statement.

b. A Boolean variable or expression evaluates to NULL.

c. A Boolean variable or expression evaluates to TRUE.

d. A Boolean variable or expression evaluates to FALSE.

e. The specified number of iteration has been performed.

Answer: d

08. Evaluate this PL/SQL block:

DECLARE

v_rows_updated NUMBER(2);

BEGIN

UPDATE inventory

SET price = price * 1.15

WHERE manufacturer_id = 10;

 v_rows_updated := SQL%ROWCOUNT;

END;

Which value will be assigned to the variable V_ROWS_UPDATED if no rows are updated?

Which value would be displayed?

a. 0

b. 1

c. 2

d. True.

e. False.

f. Null.

Answer: a

09. Evaluate this PL/SQL Block:

BEGIN

UPDATE    teacher

SET            salary = salary * 1.05

WHERE     subject_id IN (101, 102, 103);

COMMIT;

EXCEPTION

WHEN SQL%NOTFOUND = TRUE THEN

dbms_output.put_line(TO_CHAR(SQL%ROWCOUNT));

END;

What would cause output to be displayed?

a. An error occurs.

b. No rows were updated.

c. Only one row was updated.

d. More than one row was updated.

Answer: d

10. In the executable section of a PL/SQL block, you include this statement:

a. A constant will be assigned a value.

b. A scalar variable will be assigned a value.

c. A PL/SQL table element will be assigned a number value.

d. A PL/SQL table element will be assigned a character string value.

Answer: b, c, d

11. Choose two answers that are true. A variable is defined as %TYPE.

a. If the underlying table column data type changes, the PL/SQL code need to be changed.

b. You do not have to know the data type or expressions of that column.

c. Only Character variable can be defined using %TYPE.

d. You need not be concerned about changes may be made to column definitions. 

Answer: b,d

Post a Comment

0 Comments