Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

PL/SQL Exam Part 1 (10 pts each)

1. Rewrite the following IF statement to get rid of unnecessary nested IF’s.

IF salary < 10000


THEN
bonus := 2000;
ELSE
IF salary < 20000
THEN
bonus := 1500;
ELSE
IF salary < 40000
THEN
bonus := 1000;
ELSE
bonus := 500;
END IF;
END IF;
END IF;

2. How many times does the following loop execute?

FOR x IN REVERSE 12 .. 1 LOOP


calc_sales (x);
END LOOP;

3. Supply the missing symbols or keywords to correct the code.

v_num1 NUMBER;
v_char1 VARCHAR2(100);
BEGIN
v_num1 := 10
IF v_num1 > 20 THEN
v_char1 = ‘The value of variable v_num1 is greater than 20’;
ELSE
v_char1 := ‘The value of variable v_num1 is less than 20’;
END;

4. Re-write the PL/SQL block and add the missing cursor-related statement.

DECLARE
CURSOR emp_cur IS SELECT * FROM employees;
emp_rec emp_cursor%ROWTYPE;
BEGIN
OPEN emp_cur;
FETCH emp_cur INTO emp_rec;
END;

5. Remove the unnecessary code from the PL/SQL block below:

DECLARE
CURSOR emp_cur IS
SELECT last_name, department_id, employee_id
FROM employees
WHERE salary < 2500;
emp_rec emp_cur%ROWTYPE;
BEGIN
FOR emp_rec IN emp_cur
LOOP
give_raise (emp_rec.employee_id, 10000);
END LOOP;
END;

You might also like