Unit 5 - Practice Quiz

INT306

1 Which component of a database programming block is used to trap and handle runtime errors?

A. Declaration Section
B. Execution Section
C. Exception Handling Section
D. Header Section

2 In PL/SQL and T-SQL, which keyword is used to define a conditional control structure that executes a sequence of statements only if a condition is true?

A. LOOP
B. IF
C. CASE
D. WHILE

3 Which of the following statements regarding Stored Procedures is FALSE?

A. They can reduce network traffic.
B. They are compiled and stored in the database.
C. They must always return a value to the caller.
D. They can improve security by encapsulating logic.

4 What is the primary purpose of a Cursor in database programming?

A. To trigger an event automatically.
B. To handle row-by-row processing of a result set.
C. To define the structure of a table.
D. To store a compiled SQL statement permanently.

5 Which parameter mode allows a value to be passed into a stored procedure and also allows the procedure to change that value and pass it back to the calling environment?

A. IN
B. OUT
C. INOUT (or IN OUT)
D. RETURN

6 When using a cursor, which command is used to retrieve the current row from the result set and advance the cursor pointer to the next row?

A. OPEN
B. SELECT
C. FETCH
D. GET

7 Which type of Trigger is executed once for every row affected by a DML statement (INSERT, UPDATE, DELETE)?

A. Statement-level Trigger
B. Row-level Trigger
C. System Trigger
D. INSTEAD OF Trigger

8 What does the cursor attribute %%NOTFOUND return?

A. It returns TRUE if the last FETCH returned a row.
B. It returns the number of rows fetched so far.
C. It returns TRUE if the last FETCH failed to return a row.
D. It returns the text of the SQL statement.

9 Which programming construct is conceptually similar to a 'view' that allows parameters?

A. Stored Procedure
B. Trigger
C. Scalar Function
D. Table-Valued Function

10 In the context of exception handling, what does the RAISE statement do?

A. It increases the priority of the transaction.
B. It explicitly generates an exception or error.
C. It recovers the database from a crash.
D. It creates a new trigger.

11 Which of the following is NOT a valid cursor attribute?

A. %FOUND
B. %ISOPEN
C. %ROWCOUNT
D. %TYPE

12 What is the difference between a Function and a Stored Procedure regarding SQL statements?

A. Functions can only contain DDL statements.
B. Procedures can be called from within a SELECT statement (in most DBMS), whereas Functions cannot.
C. Functions are generally called from within SQL statements (like SELECT), whereas Procedures are called using CALL or EXECUTE.
D. There is no difference.

13 An INSTEAD OF trigger is most commonly used on which database object?

A. Tables
B. Views
C. Indexes
D. Sequences

14 Which loop structure repeats a sequence of statements as long as a specified condition is true?

A. FOR loop
B. WHILE loop
C. BASIC loop
D. CURSOR loop

15 In a trigger, what do the pseudo-records NEW and OLD represent?

A. They represent the first and last rows of a table.
B. They represent the state of the row before and after the DML operation.
C. They represent the previous and next transaction IDs.
D. They are used to create new tables.

16 Which control statement evaluates a single expression and compares it against several potential values to determine which branch to execute?

A. IF-THEN-ELSE
B. WHILE
C. CASE
D. GOTO

17 A stored procedure calls stored procedure . If an unhandled exception occurs in , what generally happens?

A. The database shuts down.
B. The exception is ignored and returns successfully.
C. The exception propagates up to the calling procedure .
D. Procedure is immediately deleted.

18 Which of the following is a benefit of using Implicit Cursors?

A. They allow precise control over when to fetch rows.
B. They are automatically managed by the DBMS for single-row DML and SELECT operations.
C. They are used for fetching large result sets manually.
D. They allow the use of WHERE CURRENT OF clauses.

19 What is the purpose of the CLOSE statement in cursor management?

A. It deletes the cursor definition from the code.
B. It releases the memory and resources associated with the result set.
C. It executes the query associated with the cursor.
D. It commits the transaction.

20 Which type of trigger would you use to prevent a row from being deleted if it violates a specific complex business rule?

A. AFTER DELETE
B. BEFORE DELETE
C. AFTER INSERT
D. BEFORE UPDATE

21 Consider the following syntax: What is the purpose of WHEN OTHERS?

A. To handle only arithmetic errors.
B. To handle specific named exceptions.
C. To handle any exception not explicitly handled by previous handlers.
D. To restart the block.

22 Which variable is often used inside an exception handler to retrieve the error message associated with the exception?

A. SQLCODE
B. SQLERRM
C. %ROWCOUNT
D. NO_DATA_FOUND

23 What is a Mutating Table error in the context of triggers?

A. An error that occurs when a table's structure is changed during a transaction.
B. An error occurring when a row-level trigger attempts to query or modify the table that triggered the event.
C. An error caused by a trigger calling itself recursively indefinitely.
D. An error when a table is dropped while a trigger is firing.

24 In a FOR loop defined as FOR i IN 1..10 LOOP, what happens to the counter variable i?

A. It must be explicitly declared in the declaration section.
B. It is implicitly declared as an integer by the loop construct.
C. It must be manually incremented inside the loop.
D. It retains its value after the loop ends.

25 What is the primary difference between User-defined Exceptions and Predefined Exceptions?

A. Predefined exceptions handle logic errors; user-defined handle syntax errors.
B. Predefined exceptions are raised automatically by the system; user-defined must be declared and raised explicitly.
C. User-defined exceptions cannot have error messages.
D. There is no difference.

26 Which statement allows a programmer to exit a loop immediately, bypassing the remaining statements in the loop body?

A. CONTINUE
B. EXIT (or BREAK)
C. PASS
D. NEXT

27 To execute a Stored Procedure named Calculate_Tax with a parameter 1000, which syntax is generally used?

A. SELECT Calculate_Tax(1000);
B. EXEC Calculate_Tax(1000); or CALL Calculate_Tax(1000);
C. RUN Calculate_Tax(1000);
D. TRIGGER Calculate_Tax(1000);

28 What does the PRAGMA EXCEPTION_INIT instruction do?

A. It creates a new exception type.
B. It associates a user-defined exception name with a specific backend error code.
C. It ignores all exceptions in a block.
D. It initializes the exception handling section.

29 Which construct allows a cursor to be defined with arguments, making it dynamic?

A. Implicit Cursor
B. Parameterized Cursor
C. Reference Cursor
D. Trigger

30 When declaring a variable in a database program, the NOT NULL constraint implies:

A. The variable cannot be changed after initialization.
B. The variable must be initialized with a value and cannot be assigned NULL later.
C. The variable is a primary key.
D. The variable is visible globally.

31 Which of the following is an example of a Control Flow statement?

A. INSERT INTO
B. CREATE TABLE
C. IF...THEN...ELSE
D. COMMIT

32 If a Trigger is defined as BEFORE UPDATE OF salary ON Employees, when does it fire?

A. Before any column in the Employees table is updated.
B. Before the 'salary' column specifically is updated.
C. After the 'salary' column is updated.
D. Before a new employee is inserted.

33 What is a Compound Trigger?

A. A trigger that fires on multiple tables simultaneously.
B. A single trigger that can define actions for multiple timing points (Before Statement, Before Row, After Row, After Statement).
C. A trigger that calls a stored procedure.
D. A trigger that creates another trigger.

34 Which exception is typically raised when a SELECT INTO statement returns more than one row?

A. NO_DATA_FOUND
B. TOO_MANY_ROWS
C. ZERO_DIVIDE
D. VALUE_ERROR

35 Which statement is used to remove a stored procedure from the database?

A. DELETE PROCEDURE
B. REMOVE PROCEDURE
C. DROP PROCEDURE
D. ALTER PROCEDURE

36 What is the result of the expression: in most database programming languages?

A. 5
B.
C. NULL
D. Error

37 The WHERE CURRENT OF cursor_name clause is used in UPDATE or DELETE statements to:

A. Update or delete the most recently fetched row by the cursor.
B. Update or delete all rows in the cursor.
C. Update or delete rows that match a WHERE condition in the table.
D. Close the cursor.

38 Which of the following is TRUE about Deterministic Functions?

A. They return different results for the same input values.
B. They always return the same result given the same input values.
C. They use random number generators.
D. They cannot be used in function-based indexes.

39 In the context of Loops, what does the CONTINUE statement do?

A. Terminates the loop entirely.
B. Skips the remainder of the current iteration and proceeds to the next iteration.
C. Pauses the loop execution.
D. Restarts the loop from index 1.

40 Which parameter type is the default if no mode is specified in a stored procedure declaration?

A. OUT
B. INOUT
C. IN
D. REF

41 What is the primary benefit of using exception handling in database scripts?

A. To make the code run faster.
B. To prevent the application from crashing and to manage transactions gracefully (e.g., Rollback).
C. To automatically correct data errors.
D. To increase database storage size.

42 Which cursor attribute returns the number of rows fetched so far (for explicit cursors) or rows affected (for implicit cursors)?

A. %ROWCOUNT
B. %COUNT
C. %NUMROWS
D. %FOUND

43 What is the 'Execution Order' of a database block?

A. Declarations Exception Handling Execution
B. Execution Declarations Exception Handling
C. Declarations Execution Exception Handling
D. Exception Handling Declarations Execution

44 Which statement allows you to pass a cursor variable (REF CURSOR) as a parameter to a stored procedure?

A. It is not possible to pass cursors.
B. By declaring the parameter type as SYS_REFCURSOR or a generic cursor type.
C. By converting the cursor to a string.
D. By using an array.

45 Which of the following is an example of a Searched CASE statement?

A. CASE selector WHEN value THEN result END
B. CASE WHEN grade > 90 THEN 'A' WHEN grade > 80 THEN 'B' END
C. IF grade > 90 THEN 'A' END IF
D. SWITCH(grade)

46 Why are Triggers generally avoided for returning data to the user?

A. They are too slow.
B. They are event-driven and run in the background; they are not designed to return result sets.
C. They cannot access tables.
D. They do not support SQL.

47 Can a Stored Procedure call itself recursively?

A. No, recursion is not supported in SQL.
B. Yes, provided the recursion depth limit is not exceeded.
C. Only if it is a function, not a procedure.
D. Yes, but only once.

48 What is the status of a cursor immediately after it is OPENed but before the first FETCH?

A. It points to the first row.
B. It points before the first row.
C. It points to the last row.
D. It is closed.

49 In exception handling, what happens if an exception is raised inside an exception handler?

A. The program crashes immediately.
B. The exception is handled by the same handler recursively.
C. The exception propagates to the enclosing block (or calling environment).
D. The transaction commits automatically.

50 Which keyword is used to start the execution block in a PL/SQL or standard SQL procedure?

A. START
B. GO
C. BEGIN
D. RUN