PL/SQL Cursors, Triggers and Exceptions Practice Questions Set 2

PL/SQL questions on implicit and explicit cursors, cursor attributes, database triggers, mutating tables and exception handling. This set has 23 multiple-choice questions, each with a short explanation (set 2 of 2). Click Start quiz to answer one question at a time and get instant feedback, or use Study mode to read every question with its answer.

All 23 questions with answers

  1. What are the restrictions on BEFORE trigger
    1. You cannot specify a BEFORE trigger on a view or an object view
    2. You cannot perform DML with BEFORE trigger
    3. You can write to the :NEW value but not to the :OLD value.
    4. Option 1,3
    Show answer

    Answer: D. Option 1,3

    BEFORE triggers cannot be defined on views (use INSTEAD OF), and a row-level BEFORE trigger can change :NEW but never :OLD.

  2. What are the restrictions on AFTER trigger
    1. You cannot specify an AFTER trigger on a view or an object view
    2. You cannot write either the :OLD or the :NEW value.
    3. Option 1,2
    Show answer

    Answer: C. Option 1,2

    AFTER triggers cannot be defined on views and cannot change :NEW or :OLD, because the row has already been written.

  3. What are the restrictions on INSTEAD OF triggers
    1. INSTEAD OF triggers are valid only for views.
    2. You can read both the :OLD and the :NEW value, but you cannot write either the :OLD or the :NEW value.
    3. You cannot specify UPDATE OF for an INSTEAD OF trigger
    4. all of the above
    Show answer

    Answer: D. all of the above

    INSTEAD OF triggers work only on views, are always row-level, can read but not write :OLD and :NEW, and do not support UPDATE OF column lists.

  4. Can we use a subquery in FOR clause?
    1. Yes, Instead of a cursor we can use subquery in the FOR clause
    2. No, We cannot use subquery in FOR clause
    Show answer

    Answer: A. Yes, Instead of a cursor we can use subquery in the FOR clause

    FOR rec IN (SELECT …) LOOP is an implicit cursor FOR loop that uses a subquery instead of a declared cursor.

  5. How to disable multiple triggers on a table at a time?
    1. ALTER TABLE table_name DISABLE;
    2. ALTER TABLE table_name DISABLE ALL TRIGGERS;
    3. DROP TRIGGER trigger1,trigger2,…,triggern ON table_name;
    4. ALTER TRIGGER trigger1,trigger2,…triggern ON table_name DISABLE;
    Show answer

    Answer: B. ALTER TABLE table_name DISABLE ALL TRIGGERS;

    ALTER TABLE table_name DISABLE ALL TRIGGERS; disables them all. ENABLE ALL TRIGGERS turns them back on.

  6. Cursor variable cannot be declared in a package specification
    1. TRUE
    2. FALSE
    Show answer

    Answer: A. TRUE

    Cursor variables cannot be declared in a package specification because they cannot keep state there. The REF CURSOR type itself can be declared.

  7. What are the restrictions on Cursor variable?
    1. Cannot assign NULL to cursor variable
    2. Cannot use comparison operators to test cursor variable for equality,inequality or nullity
    3. Database columns cannot store the values of cursor variable.
    4. all of the above
    Show answer

    Answer: D. all of the above

    You cannot assign NULL to a cursor variable, compare cursor variables with =, <> or IS NULL, or store them in table columns.

  8. What are the cursor attribute used in PL/SQl?
    1. %ROWCOUNT
    2. %CURSOROPEN
    3. %NOTFOUND
    4. option,1,3
    Show answer

    Answer: D. option,1,3

    The cursor attributes are %FOUND, %NOTFOUND, %ROWCOUNT and %ISOPEN. %CURSOROPEN does not exist.

  9. _______provides the record type that represents a entire row of a table or view or columns selected in the cursor
    1. %ROWTYPE
    2. %TYPE
    3. %DATATYPE
    4. %ROWCOUNT
    Show answer

    Answer: A. %ROWTYPE

    %ROWTYPE declares a record that matches a table, view or cursor row.

  10. Which all are the different types of database trigger?
    1. Row-level triggers
    2. Statement level triggers
    3. instead of triggers
    4. all of these
    Show answer

    Answer: D. all of these

    Row-level, statement-level and INSTEAD OF are DML trigger types. Oracle also has DDL and system event triggers.

  11. Which are the PL/SQL statement used in Cursor processing?
    1. CURSOR Cursor_name
    2. OPEN Cursor name
    3. FETCH .. INTO …
    4. all of these
    Show answer

    Answer: D. all of these

    Explicit cursors use CURSOR to declare, OPEN, FETCH … INTO and CLOSE.

  12. The _____________ tells the compiler to associate an exception with an oracle error.
    1. PRAGMA_EXCEPTION_INIT
    2. EXCEPTION
    3. Raise_application_error
    4. TOO_MANY_ROWS
    Show answer

    Answer: A. PRAGMA_EXCEPTION_INIT

    PRAGMA EXCEPTION_INIT(my_exc, -2292) links a named exception to an Oracle error number so you can handle it by name.

  13. is a procedure of package DBMS which allows to issue user_defined error message
    1. PRAGMA_EXCEPTION_INIT
    2. EXCEPTION
    3. Raise_application_error
    4. TOO_MANY_ROWS
    Show answer

    Answer: C. Raise_application_error

    RAISE_APPLICATION_ERROR(-20000 to -20999, ‘message’) raises a user-defined error. It is supplied in DBMS_STANDARD.

  14. What is the use of DBMS_OUTPUT
    1. To handle errors
    2. to display the output
    3. used as an exception handler
    4. to create an output file
    Show answer

    Answer: B. to display the output

    DBMS_OUTPUT writes messages that SQL*Plus or SQL Developer display. It is used mostly for debugging.

  15. Which one of these is not a valid privilege
    1. CREATE TYPE
    2. CREATE TRIGGER
    3. CREATE FILE
    4. CREATE TABLE
    Show answer

    Answer: C. CREATE FILE

    CREATE TYPE, CREATE TRIGGER and CREATE TABLE are system privileges. There is no CREATE FILE privilege.

  16. Which exception is raised when we assign the wrong type of value to a variable
    1. ILLEGAL
    2. WRONG_DATA_TYPE
    3. UNHANDLED
    4. VALUE_ERROR
    Show answer

    Answer: D. VALUE_ERROR

    VALUE_ERROR (ORA-06502) is raised on conversion, truncation or size errors, such as putting text into a NUMBER variable.

  17. Which of these are predefined exceptions
    1. no_data_found
    2. too_many_rows
    3. invalid_cursor
    4. All of the above
    Show answer

    Answer: D. All of the above

    NO_DATA_FOUND, TOO_MANY_ROWS and INVALID_CURSOR are all predefined exceptions.

  18. Name a few implicit cursor attributes
    1. %FOUND
    2. %ROWCOUNT
    3. %NOTFOUND
    4. All of the above
    Show answer

    Answer: D. All of the above

    SQL%FOUND, SQL%NOTFOUND and SQL%ROWCOUNT describe the most recent implicit cursor (a DML statement or SELECT INTO).

  19. What are the types of cursors
    1. implict
    2. explicit
    3. A&B
    4. defined
    Show answer

    Answer: C. A&B

    Oracle creates an implicit cursor for every SQL statement; explicit cursors are the ones you declare yourself.

  20. Which attribute can tell the number of rows fetched so far for the cursor
    1. %count
    2. %rowcount
    3. %recordcount
    4. %total
    Show answer

    Answer: B. %rowcount

    %ROWCOUNT returns the number of rows fetched so far.

  21. Triggers are fired in response to the following events
    1. A row is inserted into a table
    2. A row in a table is updated
    3. A row in a table is deleted
    4. All of the above
    Show answer

    Answer: D. All of the above

    DML triggers fire when rows are inserted, updated or deleted.

  22. Is it possible to use Commit/rollback in Exception ?
    1. YES
    2. NO
    Show answer

    Answer: A. YES

    An exception handler can COMMIT or ROLLBACK, for example to undo the work and log the error.

  23. In PL/SQL , we write select statement with INTO clause, this mat returns which all exceptions??
    1. NO_DATA_FOUND
    2. TOO_MANY_ROWS
    3. INVALID_CURSOR
    4. Option1,2
    Show answer

    Answer: D. Option1,2

    SELECT INTO raises NO_DATA_FOUND when no row is found and TOO_MANY_ROWS when more than one row comes back.

More Oracle practice questions

These questions come from interview and training material collected over years of Oracle EBS project work by Amol Jadhav. They are not copied from Oracle certification exams.