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
- What are the restrictions on BEFORE trigger
- You cannot specify a BEFORE trigger on a view or an object view
- You cannot perform DML with BEFORE trigger
- You can write to the :NEW value but not to the :OLD value.
- 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.
- What are the restrictions on AFTER trigger
- You cannot specify an AFTER trigger on a view or an object view
- You cannot write either the :OLD or the :NEW value.
- 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.
- What are the restrictions on INSTEAD OF triggers
- INSTEAD OF triggers are valid only for views.
- You can read both the :OLD and the :NEW value, but you cannot write either the :OLD or the :NEW value.
- You cannot specify UPDATE OF for an INSTEAD OF trigger
- 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.
- Can we use a subquery in FOR clause?
- Yes, Instead of a cursor we can use subquery in the FOR clause
- 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.
- How to disable multiple triggers on a table at a time?
- ALTER TABLE table_name DISABLE;
- ALTER TABLE table_name DISABLE ALL TRIGGERS;
- DROP TRIGGER trigger1,trigger2,…,triggern ON table_name;
- 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.
- Cursor variable cannot be declared in a package specification
- TRUE
- 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.
- What are the restrictions on Cursor variable?
- Cannot assign NULL to cursor variable
- Cannot use comparison operators to test cursor variable for equality,inequality or nullity
- Database columns cannot store the values of cursor variable.
- 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.
- What are the cursor attribute used in PL/SQl?
- %ROWCOUNT
- %CURSOROPEN
- %NOTFOUND
- option,1,3
Show answer
Answer: D. option,1,3
The cursor attributes are %FOUND, %NOTFOUND, %ROWCOUNT and %ISOPEN. %CURSOROPEN does not exist.
- _______provides the record type that represents a entire row of a table or view or columns selected in the cursor
- %ROWTYPE
- %TYPE
- %DATATYPE
- %ROWCOUNT
Show answer
Answer: A. %ROWTYPE
%ROWTYPE declares a record that matches a table, view or cursor row.
- Which all are the different types of database trigger?
- Row-level triggers
- Statement level triggers
- instead of triggers
- 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.
- Which are the PL/SQL statement used in Cursor processing?
- CURSOR Cursor_name
- OPEN Cursor name
- FETCH .. INTO …
- all of these
Show answer
Answer: D. all of these
Explicit cursors use CURSOR to declare, OPEN, FETCH … INTO and CLOSE.
- The _____________ tells the compiler to associate an exception with an oracle error.
- PRAGMA_EXCEPTION_INIT
- EXCEPTION
- Raise_application_error
- 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.
- is a procedure of package DBMS which allows to issue user_defined error message
- PRAGMA_EXCEPTION_INIT
- EXCEPTION
- Raise_application_error
- 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.
- What is the use of DBMS_OUTPUT
- To handle errors
- to display the output
- used as an exception handler
- 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.
- Which one of these is not a valid privilege
- CREATE TYPE
- CREATE TRIGGER
- CREATE FILE
- CREATE TABLE
Show answer
Answer: C. CREATE FILE
CREATE TYPE, CREATE TRIGGER and CREATE TABLE are system privileges. There is no CREATE FILE privilege.
- Which exception is raised when we assign the wrong type of value to a variable
- ILLEGAL
- WRONG_DATA_TYPE
- UNHANDLED
- 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.
- Which of these are predefined exceptions
- no_data_found
- too_many_rows
- invalid_cursor
- 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.
- Name a few implicit cursor attributes
- %FOUND
- %ROWCOUNT
- %NOTFOUND
- 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).
- What are the types of cursors
- implict
- explicit
- A&B
- defined
Show answer
Answer: C. A&B
Oracle creates an implicit cursor for every SQL statement; explicit cursors are the ones you declare yourself.
- Which attribute can tell the number of rows fetched so far for the cursor
- %count
- %rowcount
- %recordcount
- %total
Show answer
Answer: B. %rowcount
%ROWCOUNT returns the number of rows fetched so far.
- Triggers are fired in response to the following events
- A row is inserted into a table
- A row in a table is updated
- A row in a table is deleted
- All of the above
Show answer
Answer: D. All of the above
DML triggers fire when rows are inserted, updated or deleted.
- Is it possible to use Commit/rollback in Exception ?
- YES
- NO
Show answer
Answer: A. YES
An exception handler can COMMIT or ROLLBACK, for example to undo the work and log the error.
- In PL/SQL , we write select statement with INTO clause, this mat returns which all exceptions??
- NO_DATA_FOUND
- TOO_MANY_ROWS
- INVALID_CURSOR
- 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.
