Sie sind auf Seite 1von 5

Test: Quiz: Conditional Control: IF Statements 1.

Look at the following (badly written) code: age := 5; IF age<30 THEN mature := 'adult'; ELSIF age<22 THEN mature := 'teenager'; ELSIF age<13 THEN mature := 'child'; END IF; DBMS_OUTPUT.PUT_LINE(mature); What will be displayed when this code is executed? Mark for Review (1) Points child teenager adult (*) adultteenagerchild

Correct 2. What will be displayed when this block is executed? DECLARE v_birthdate DATE; BEGIN IF v_birthdate < '01-JAN-2000' THEN DBMS_OUTPUT.PUT_LINE(' Born in the 20th century '); ELSE DBMS_OUTPUT.PUT_LINE(' Born in the 21st century '); END IF; END; Mark for Review (1) Points Born in the 20th century Born in the 21st century (*) Exception raised because no date given

Incorrect. Refer to Section 4 Lesson 1. 3. Name three types of control structures in PL/SQL. (Choose three) Mark for Review (1) Points

(Choose all correct answers) LOOP statements (*) SELECT statements EXCEPTIONS IF statements (*) CASE statements (*)

Incorrect. Refer to Section 4 Lesson 1. 4. You want to repeat a set of statements 100 times, incrementing a counte r each time. What kind of PL/SQL control structure would you use? Mark for Review (1) Points IF...THEN...ELSE IF...THEN...ELSIF...ELSE CASE...WHEN...THEN A loop. (*)

Correct 5. A basic loop is a type of control structure used to change the logical flow of statements in a PL/SQL block. True or False? Mark for Review (1) Points True (*) False

Correct 6. What is wrong with the following trivial IF statement: IF (v_job='President')

THEN v_salary := 10000; Mark for Review (1) Points IF and THEN must be on the same line: IF (v_job='President') THEN ... The condition should be coded: IF (v_job := 'President') END IF; is missing (*) ELSE is missing

Correct 7. What will be displayed when this block is executed? DECLARE v_bool1 BOOLEAN := TRUE; v_bool2 BOOLEAN; v_char VARCHAR(4) := 'up'; BEGIN IF (v_bool1 AND v_bool2) THEN v_char:='down'; ELSE v_char:='left'; END IF; DBMS_OUTPUT.PUT_LINE(v_char); END; Mark for Review (1) Points up down left (*) null

Correct 8. What will be displayed when this block is executed? DECLARE v_bool1 BOOLEAN := NULL; v_bool2 BOOLEAN := NULL; v_char VARCHAR(10) := 'Start'; BEGIN IF (v_bool1 = v_bool2) THEN

v_char:='Equal'; ELSE v_char:='Not equal'; END IF; DBMS_OUTPUT.PUT_LINE(v_char); END; Mark for Review (1) Points Equal Not equal (*) Start Nothing will be displayed. The block will fail because you cannot compar e two null values.

Correct 9. We want to execute one of three statements depending on whether the valu e in V_VAR is 10, 20 or some other value. What should be coded at Line A? IF v_var = 10 THEN statement1; -- Line A statement2; ELSE statement3; END IF; Mark for Review (1) Points ELSE IF v_var = 20 THEN ELSIF v_var = 20 ELSIF v_var = 20 THEN (*) IF v_var = 20 THEN

Correct 10. Which one of the following is correct syntax for an IF statement? Mark for Review (1) Points IF condition THEN DO

statement1; statement2; END IF; IF condition THEN statement1; statement2; END IF; (*)

IF condition THEN statement1; statement2; ENDIF; IF condition THEN statement1; AND statement2; END IF;

Correct 11. Which of the following statements are true about any of the PL/SQL cond itional control structures such as IF ... , CASE ... and loops? Mark for Review (1) Points They allow the programmer to use logical tests to determine which statem ents are executed and which are not. They allow a set of statements to be executed repeatedly (i.e. more than once). They determine a course of action based on conditions. All of the above. (*)

Correct