wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PL/SQL Brain Bowl Championship!

Total questions: 50

Worksheet time: 3hrs 30mins

Name
Class
Date
1.

After a cursor has been closed, it can be opened again in the same PL/SQL block.

a)

True

b)

False

2.

For which type of SQL statement must you use an explicit cursor?

a)

Data Definition Language (DDL) statements

b)

DML statements that process more than one row

c)

Queries that return a single row

d)

Queries that return more than one row

3.

What is wrong with this code?

a)

Nothing is wrong; all the rows will be FETCHed and displayed

b)

The CLOSE statement should be coded after END LOOP;

c)

The EXIT WHEN... statement should be coded outside the loop

d)

The OPEN statement should be inside the loop

4.

Which of the following is a benefit of using a cursor FOR loop?

a)

The exception handling is done automatically

b)

Because there is less code, the loop executes faster

c)

%ROWCOUNT increments automatically each time a row is FETCHed

d)

The OPEN, CLOSE, FETCH and EXIT from the loop are done automatically

5.

How many explicit cursors can be declared and used in a single PL/SQL block?

a)

Only one

b)

One or two

c)

Up to eight cursors

d)

As many as needed

6.

Which of the following is a good reason to use two cursors in a single PL/SQL block?

a)

When two tables are related to each other (often by a foreign key), and we want to produce a multilevel report using data from both tables

b)

To allow one cursor to be opened twice at the same time

c)

To allow rows to be locked as they are FETCHed

d)

To speed up the execution of the PL/SQL block

7.

How many attributes can be accessed with v_dept_info_rec in this code?

a)

One

b)

Two

c)

Three

d)

Four

8.

An attempt to insert a null value into a NOT NULL table column raises an ORA-01400 exception. How can you code an exception handler to trap this exception?

a)

Declare a variable as follows: e_null_excep EXCEPTION := -01400; Then test for WHEN e_null_excep in the exception section

b)

Declare a variable e_null_excep of type EXCEPTION, associate it with ORA-01400 using a PRAGMA directive, and test for WHEN e_null_excep in the exception section

c)

Declare a variable e_null_excep of type VARCHAR2, associate it with ORA-01400 using a PRAGMA directive, and test for WHEN e_null_excep in the exception section

d)

Test for WHEN ORA-1400 in the exception section

9.

An attempt to update an employee's salary to a negative value will violate a check constraint and raise an ORA-02290 exception. Which of the following is a correct definition of a handler for this exception?

a)

DECLARE e_sal_excep EXCEPTION;

PRAGMA EXCEPTION_INIT(-02290, e_sal_excep);

b)

DECLARE e_sal_excep EXCEPTION;

PRAGMA EXCEPTION_INIT(e_sal_excep, -02290);

c)

DECLARE e_sal_excep EXCEPTION;

PRAGMA EXCEPTION_INIT(e_sal_excep, 02290);

d)

DECLARE e_sal_excep EXCEPTION; PRAGMA_EXCEPTION_INIT(e_sal_exception, -02290);

10.

Department_id 99 does not exist. What will be displayed when this code is executed?

a)

ORA-20201: Department does not exist

b)

ORA-01403: No Data Found

c)

ORA-01403: No Data Found ORA-20201: Department does not exist

11.

This exception handler will successfully insert the Oracle error number and error message into a log table whenever an Oracle Server error occurs. (Assume that err_log_table has been created with suitable columns and datatypes)

a)

True

b)

False

12.

What will happen when this code is executed?

a)

The code will execute successfully and 'Outer Raised' will be displayed

b)

The code will fail to compile because e_inner_excep cannot be referenced in the outer block

c)

The code will fail to compile because e_inner_excep was declared but never RAISEd

d)

The code will propagate the e_outer_excep back to the calling environment

13.

There are three employees in department 90. What will be displayed when this code is executed?

a)

An unhandled exception will be propagated back to the calling environment

b)

Message 1

c)

Message 1 Message 3 Message 4

d)

Message 1 Message 4

14.

User-defined exceptions must be declared explicitly by the programmer, but then are raised automatically by the Oracle Server.

a)

True

b)

False

15.

No employees are in department_id 99. What output will be displayed when this code is executed?

a)

Department 99 is empty

b)

No employees found

c)

No employees found - Department 99 is empty

d)

The block will fail because you cannot explicitly RAISE a predefined Oracle Server error such as NO_DATA_FOUND

16.

Which of the following is the actual parameter?

a)

p_param

b)

'Smith'

c)

v_param

d)

None of these

17.

A programmer creates a PL/SQL subprogram which is compiled and stored in the database. Two separate users then execute an application which invokes this subprogram four times. How many times must the subprogram be recompiled?

a)

Zero times

b)

One time

c)

Two times

d)

Four times

e)

Eight times

18.

Which statement is true regarding this subprogram?

a)

The subprogram cannot do a COMMIT

b)

The subprogram will fail because the RETURN is not specified

c)

The subprogram's success depends on the calling program

d)

The subprogram's success is independent of the calling program

19.

Examine this code (the code of CHILD2 is not shown). Employee_id 9999 does not exist. What happens when PARENT is executed?

a)

CHILD1 ends abruptly, and PARENT handles the exception successfully and ends - CHILD2 does not execute

b)

CHILD1 ends abruptly, and then PARENT also ends abruptly with an unhandled exception

c)

CHILD1 handles the exception successfully and ends. PARENT continues to execute and invokes CHILD2

d)

PARENT fails to compile because you cannot have the same exception handler in two separate subprograms

e)

PARENT handles the exception, and then CHILD1 resumes execution

20.

A function must have at least one IN parameter, and must return exactly one value.

a)

True

b)

False

21.

What is wrong with this code?

a)

P_PARAM must be declared AFTER the RETURN clause

b)

P_PARAM must have a default value

c)

RETURN (p_param > 10); is wrong because you cannot return an expression

d)

The datatype of the IN parameter cannot have a precision or scale. It must be NUMBER, not NUMBER(4)

e)

The NUMBER datatype must have a scale as well as a precision

22.

What will be displayed when this code is executed?

a)

8

b)

12

c)

20

d)

varB

e)

Nothing, the block will fail with an error

23.

A Scalar data type holds a(n) ____ value.

a)

Image

b)

Large

c)

Multi

d)

Single

24.

Which of these is NOT a valid cursor declaration?

a)

CURSOR emp_curs IS SELECT salary FROM employees ORDER BY salary DESC;

b)

CURSOR emp_curs IS SELECT salary FROM employees WHERE last_name LIKE 'S%';

c)

CURSOR emp_curs IS SELECT salary INTO v_salary FROM employees;

d)

CURSOR emp_dept_curs IS SELECT e.salary, d.department_name FROM employees e, departments d WHERE e.department_id = d.department_id;

25.

If you use the %TYPE attribute, you can avoid hard-coding the column name.

a)

True

b)

False

26.

What happens when this block of code finish running?

a)

You get an error; you cannot COMMIT twice in a row

b)

You have nothing new; the last ROLLBACK undid the INSERTs

c)

You have the rows added twice; there are four new rows

d)

You have the two new rows added

27.

There are three employees in department 90. What will be displayed when this code is executed?

a)

NO 3

b)

YES 1

c)

YES 3

d)

Nothing will be displayed - the block will fail because you cannot use implicit cursor attributes directly in a call to DBMS_OUTPUT.PUT_LINE

28.

Given this first section of code - which statement will always return exactly one value?

a)

SELECT salary INTO v_result FROM employees;

b)

SELECT salary INTO v_result FROM employees WHERE department_id = 80;

c)

SELECT salary INTO v_result FROM employees WHERE last_name ='Smith';

d)

SELECT SUM(salary) INTO v_result FROM employees;

29.

What is the value of GAME at the end of this block of code?

a)

False

b)

NULL

c)

'lost'

d)

'won'

30.

What will be displayed when this code is executed?

a)

Equal

b)

Undefined

c)

Unequal

d)

Nothing will be displayed because V_MESSAGE is set to NULL

31.

How many times will the SELECT statement execute in this code?

a)

Once

b)

Twice

c)

An infinite number of times because the EXIT condition will never be true

d)

Never (the SELECT will not execute at all)

32.

Which of these is NOT a valid cursor declaration?

a)

CURSOR emp_curs IS SELECT salary FROM employees ORDER BY salary DESC;

b)

CURSOR emp_curs IS SELECT salary FROM employees WHERE last_name LIKE 'S%';

c)

CURSOR emp_curs IS SELECT salary INTO v_salary FROM employees;

d)

CURSOR emp_dept_curs IS SELECT e.salary, d.department_name FROM employees e, departments d WHERE e.department_id = d.department_id;

33.

Which of the following statements successfully opens the cursor and fetches the first row of the active set in this code?

a)

OPEN emp_curs; FETCH emp_curs;

b)

OPEN emp_curs; FETCH emp_curs INTO v_last_name, v_salary;

c)

OPEN emp_curs; FETCH emp_curs INTO v_salary, v_last_name;

d)

OPEN emp_curs; FETCH FIRST emp_curs INTO v_last_name, v_salary;

34.

To display the salary of an employee, what must be coded at Point A in this code?

a)

employees.salary

b)

emp_curs.salary

c)

emp_rec.salary

d)

emp_rec.salary IN emp_curs

e)

salary

35.

This line of code is correct.

a)

True

b)

False

36.

Procedure ins_emp accepts an employee_id as an IN parameter and attempts to insert a row with that employee_id into the EMPLOYEES table. Ins_emp does not contain an exception section. A second procedure is created as shown.
When call_ins_emp is executed, (assuming Auto-commit is turned on), which rows will be inserted into the EMPLOYEES table?

a)

99 only

b)

99 and 999

c)

999 only

d)

No rows will be inserted

37.

What is wrong with this code?

a)

Nothing is wrong, the trigger will execute correctly

b)

The trigger body is reading the same table (employees) that the triggering event is updating

c)

You can never use SELECT inside a DML trigger

d)

You cannot use a DECLARE statement in a trigger

e)

You must use RAISE_APPLICATION_ERROR in a BEFORE trigger

38.

A database trigger is a PL/SQL stored subprogram which is explicitly invoked just like a procedure or a function.

a)

True

b)

False

39.

Which of the following could NOT be done by a database trigger?

a)

Enforcing a complex business rule

b)

Enforcing a complex database security check

c)

Ensuring that a student never arrives late for a class

d)

Keeping a log of how many rows have been inserted into a table

e)

Recalculating the total salary bill for a department whenever an employee's salary is changed

40.

You can use a trigger to prevent rows from being deleted from the EMPLOYEES table on Mondays.

a)

True

b)

False

41.

User AYSEGUL successfully creates this trigger. User AYSEGUL then tries to drop the LOCATIONS table. What will happen?

a)

An error message is displayed because you cannot drop a table that is associated with a trigger

b)

Both the table and the trigger are dropped

c)

The table is dropped and the trigger is disabled

d)

The trigger is dropped but the table is not dropped

42.

A DML statement trigger fires only once for each triggering DML statement, while a row trigger fires once for each row processed by the triggering statement.

a)

True

b)

False

43.

Which of the following is the correct syntax for creating a DML trigger associated with the EMPLOYEES table? The trigger must fire whenever an employee's JOB_ID is updated, but not if a different column is updated.

a)

CREATE TRIGGER job_upd_trigg AFTER UPDATE OF job_id ON employees

BEGIN ...

b)

CREATE TRIGGER job_upd_trigg AFTER UPDATE ON employees.job_id BEGIN ...

c)

CREATE TRIGGER job_upd_trigg AFTER UPDATE ON employees(job_id) BEGIN ...

d)

CREATE TRIGGER job_upd_trigg WHENEVER UPDATE OF job_id IN employees

BEGIN ...

44.

What is wrong with this code?

a)

Nothing is wrong, this trigger will compile and execute successfully

b)

The last line should be: END loc_trigg;

c)

The second line should be: BEFORE DELETE OF locations

d)

You cannot use RAISE_APPLICATION_ERROR inside a trigger

e)

You cannot use ROLLBACK inside a trigger

45.

Examine this code. To create a row trigger, what code should be included at Line A?

a)

FOR ALL ROWS

b)

FOR EACH ROW

c)

FOR EACH AND EVERY ROW

d)

FOR EVERY ROW

e)

Nothing is needed because DML triggers are row triggers by default

46.

PL/SQL procedure A invokes procedure B, which in turn invokes procedure C, which references table T. If table T is dropped, which of the following statements is true?

a)

A, B and C are all invalid

b)

A, B and C are all still valid

c)

B and C are invalid, but A is still valid

d)

C is invalid but A and B are still valid

47.

Examine this trigger. It should raise an application error if a user tries to update an employee's last name. It should allow updates to all other columns of the EMPLOYEES table. What should be coded at line A?

a)

IF UPDATE('LAST_NAME') THEN

b)

IF UPDATING('LAST_NAME') THEN

c)

IF UPDATING LAST_NAME THEN

d)

IF UPDATING THEN

48.

You need to create a trigger that will fire whenever an employee's salary or job_id is updated, but not when any other column of the EMPLOYEES table is updated. Which of the following is the correct syntax to do this?

a)

CREATE TRIGGER emp_upd_trigg AFTER UPDATE OF salary, job_id ON employees BEGIN ...

b)

CREATE TRIGGER emp_upd_trigg AFTER UPDATE OF salary OR job_id ON employees BEGIN ...

c)

CREATE TRIGGER emp_upd_trigg AFTER UPDATE OF (salary, job_id) ON employees BEGIN ...

d)

CREATE TRIGGER emp_upd_trigg AFTER UPDATE ON employees (salary, job_id) BEGIN ...

49.

A business rule states that an employee's salary must be between 4000 and 30000. We could enforce this rule using a CHECK constraint, but it is better to use a database trigger.

a)

True

b)

False

50.

The following variable declaration is correct:
DECLARE test NUMBER(5);

a)

True

b)

False