PL/SQL questions on implicit and explicit cursors, cursor attributes, database triggers, mutating tables and exception handling. This set has 24 multiple-choice questions, each with a short explanation (set 1 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 24 questions with answers
- How can you find, if a cursor is open in a PL/SQL block?
- Status of any cursor can be determine by using %ROWTYPE cursor status variable.
- Status of any cursor can be determine by using %ISOPEN cursor status variable.
- Status of any cursor can be determine by using %ISCLOSE cursor status variable.
- Status of any cursor can be determine by using %ISEXIT cursor status variable.
Show answer
Answer: B. Status of any cursor can be determine by using %ISOPEN cursor status variable.
cursor_name%ISOPEN returns TRUE when the cursor is open and FALSE when it is closed.
- Which of the below is not a predefined exception
- dup_val_on_index
- not_logged_on
- login_dened
- None
Show answer
Answer: D. None
DUP_VAL_ON_INDEX, NOT_LOGGED_ON and LOGIN_DENIED are all predefined exceptions declared in the STANDARD package.
- How can we retrieve multiple rows in PL/SQL
- BULK COLLLECT
- REF CURSOR
- CURSOR
- all of these
Show answer
Answer: D. all of these
You can process many rows with a cursor loop, a REF CURSOR, or BULK COLLECT INTO a collection.
- Syntax for database triggers
- CREATE OR REPLACE TRIGGER <trigger_name> {BEFORE|AFTER} verb_list ON <table_name> [FOR EACH ROW] <variable list> BEGIN <program_code> END
- CREATE OR REPLACE <trigger_name> {BEFORE|AFTER} verb_list ON <table_name> [FOR EACH ROW] <variable list> BEGIN <program_code> END
- CREATE OR REPLACE TRIGGER <trigger_name> {BEFORE|AFTER} verb_list ON <table_name> [FOR EACH ROW] DECLARE <variable list> BEGIN <program_code> END
- None of the above
Show answer
Answer: C. CREATE OR REPLACE TRIGGER <trigger_name> {BEFORE|AFTER} verb_list ON <table_name> [FOR EACH ROW] DECLARE <variable list> BEGIN <program_code> END
The form is CREATE OR REPLACE TRIGGER name BEFORE|AFTER event ON table [FOR EACH ROW] [DECLARE …] BEGIN … END; A trigger needs DECLARE for local variables.
- Which of the below can be used in expression
- PROCEDURE
- FUNCTION
- TRIGGER
- TABLE
Show answer
Answer: B. FUNCTION
Only functions return a value, so only functions can be used inside an expression.
- Which exception is raised when PL/SQL encounters an internal error
- program_error
- internal_error
- storate_error
- others
Show answer
Answer: A. program_error
PROGRAM_ERROR (ORA-06501) is raised when PL/SQL hits an internal problem.
- Why use Truncate over Delete while deleting all rows
- truncate has an implicit commit
- it de allocates space
- truncate is efficient, triggers are not fired
- All of the above
Show answer
Answer: D. All of the above
TRUNCATE is DDL: it commits implicitly, frees space by resetting the high-water mark, does not fire DELETE triggers and is much faster than DELETE.
- what is the order of execution if there is a statement level and row level trigger on a same table? 1) Before Statement level 2)After Statement level 3)Before Row level 4)After Row level
- 1,2,3,4
- 1,3,4,2
- 3,4,1,2
- 2,1,4,3
Show answer
Answer: B. 1,3,4,2
The order is BEFORE statement, then for each row BEFORE row and AFTER row, and finally AFTER statement.
- How to control how many cursors are open in an session
- Set OPEN_CURSORS parameter in initialization parameters
- There is no absolute limit to the total number of cursors one session can have open at one time
- Set SESSION_CURSORS parameter in initialization Parameter
- Set SESSION_OPEN_CURSORS parameter in the initialization parameter
Show answer
Answer: A. Set OPEN_CURSORS parameter in initialization parameters
The OPEN_CURSORS initialization parameter sets the maximum number of cursors a session can have open.
- What is the default Value for OPEN_CURSORS parameter for a session
- 50
- 25
- 65535
- 0
Show answer
Answer: A. 50
OPEN_CURSORS defaults to 50. Many DBAs raise it to 300 or more for applications such as Oracle EBS.
- What will happen after the execution of COMMIT statement?
- The cursor having query as SELECT …. FOR UPDATE gets closed after COMMIT/ROLLBACK
- The cursor having query as SELECT…. does not get closed even after COMMIT/ROLLBACK.
- After commit statements all changes will be stored permanently in the database.
- all of these
Show answer
Answer: D. all of these
After COMMIT, changes are permanent and locks are released. A FOR UPDATE cursor can no longer be fetched (ORA-01002), while an ordinary cursor stays usable.
- Which all are the part of database trigger?
- Triggering event
- Triggering action
- A trigger constraint
- Option 1,2,3
Show answer
Answer: D. Option 1,2,3
A trigger has a triggering event, an optional restriction (the WHEN clause) and the trigger action.
- Which is not a triggering event
- INSERT
- DELETE
- UPDATE
- none of these
Show answer
Answer: D. none of these
INSERT, UPDATE and DELETE are all DML triggering events.
- Triggering Constraint is specified using _______ clause
- WHEN
- FOR EACH ROW
- PER STATEMENT
- all of these
Show answer
Answer: A. WHEN
The WHEN clause restricts a row-level trigger so it fires only when a condition is true.
- Is it possible to use transaction control statements in database triggers?
- NO
- YES
Show answer
Answer: A. NO
A normal trigger cannot COMMIT or ROLLBACK. The exception is a trigger declared with PRAGMA AUTONOMOUS_TRANSACTION.
- Which of the following statements are true ?
- For triggers related to DELETE only OLD.column_name values only available.
- For triggers related to INSERT only NEW.column_name values only available.
- For triggers related to UPDATE only OLD.column_name NEW.column_name values only available.
- All of the above
Show answer
Answer: D. All of the above
In a DELETE trigger :NEW is null, in an INSERT trigger :OLD is null, and an UPDATE trigger has both.
- What happens if a procedure that updates a column of table X is called in a database trigger of the same table ?
- Mutation of tables occurs
- Trigger is executed successfully
- the table get locked
- Will get an error message saying ” table is locked for updation by another user”
Show answer
Answer: A. Mutation of tables occurs
A row-level trigger that reads or changes its own table raises ORA-04091, the mutating table error.
- What is the Basic PL/SQL Code Structure?
- Declare(mandatory) Begin (mandatory) …… sql stmts ……PL/SQL stmts Exception(mandatory) End; (mandatory)
- Declare(mandatory) Begin (mandatory) …… sql stmts ……PL/SQL stmts Exception(optional) End; (mandatory)
- Declare (optinal) Begin (mandatory) …… sql stmts ……PL/SQL stmts Excecution (optional) End; (mandatory)
- Declare (optional) Begin (mandatory) …… sql stmts ……PL/SQL stmts Exception (Optional) End; (mandatory)
Show answer
Answer: D. Declare (optional) Begin (mandatory) …… sql stmts ……PL/SQL stmts Exception (Optional) End; (mandatory)
Only BEGIN and END are required. DECLARE and EXCEPTION are optional.
- The Procedure Body must have at least one executable statement after the BEGIN and before the END or EXCEPTION keywords Is this statement true or false.
- TRUE
- FALSE
Show answer
Answer: A. TRUE
A procedure body needs at least one executable statement. Use NULL; if there is nothing to do.
- Which statement is true regarding anonymous block
- Anonymous blocks don’t have names under which they can be stored in the database
- By using block labels, you can give a name to your block for the duration of its execution, using PL/SQL labels .
- Anonymous blocks Cannot use CURSORS
- Option 1 & Option 2
Show answer
Answer: D. Option 1 & Option 2
Anonymous blocks are not stored under a name, but a label such as <<my_block>> names them while they run. They can use cursors.
- Which is the PL/SQL procedure that are associated with tables and are called whenever certain modifications(events) occurs.
- Triggers
- Functions
- Packages
- collections
Show answer
Answer: A. Triggers
Triggers are stored blocks that fire automatically on events such as INSERT, UPDATE or DELETE on a table.
- The PL/SQL block in the structure of a trigger is a usual code block where you can place PL/SQL commands excepts COMMIT or ROLLBACK
- FALSE
- TRUE
Show answer
Answer: B. TRUE
A trigger body is normal PL/SQL, except that it cannot COMMIT or ROLLBACK unless it is an autonomous transaction.
- The PERSON table contains 5 records.An update trigger is created on the table as below CREATE OR REPLACE TRIGGER PERSON_TRIGGER BEFORE UPDATE ON PERSON BEGIN DBMS_OUTPUT.PUT_LINE(‘BEFORE UPDATING PERSON(S)’); END; What will be the result of below update statement on the table? Update PERSON SET DOB = SYSDATE;
- BEFORE UPDATING SOME PERSON(S) 5 Rows Updated
- BEFORE UPDATING SOME PERSON(S) BEFORE UPDATING SOME PERSON(S) BEFORE UPDATING SOME PERSON(S) BEFORE UPDATING SOME PERSON(S) BEFORE UPDATING SOME PERSON(S) 5 Rows Updated
- Compilation Error
- Runtime Error
Show answer
Answer: A. BEFORE UPDATING SOME PERSON(S) 5 Rows Updated
Without FOR EACH ROW this is a statement-level trigger, so it fires once for the UPDATE no matter how many rows change.
- What is the syntax to drop a trigger?
- DROP trigger_name;
- DROP TRIGGER trigger_name;
- DROP TRIGGER trigger_name ON table_name;
- DROP trigger_name ON table_name;
Show answer
Answer: B. DROP TRIGGER trigger_name;
Use DROP TRIGGER trigger_name;
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.
