This set of PL/SQL Multiple Choice Questions & Answers (MCQs) focuses on “PL/SQL Cursors”.
1. In PL/SQL, a cursor is a pointer to which of the following area?
a) Content Area
b) Contest Area
c) Context Area
d) Contact Area
View Answer
Explanation: In PL/SQL, Oracle creates a memory area known as Context area. This area contains all the information required to execute a statement. A cursor acts as a pointer to this context area and Oracle controls this area with the help of a cursor.
2. How many types of cursors are present in PL/SQL?
a) 2
b) 3
c) 4
d) 5
View Answer
Explanation: In PL/SQL, there are 2 types of cursors. These are implicit cursor and explicit cursor. Implicit cursors are the cursors which are automatically created by the Oracle wherever needed. Explicit cursors are the programmer defined cursors.
3. An explicit cursor is associated with an INSERT, UPDATE or DELETE statement.
a) True
b) False
View Answer
Explanation: An implicit cursor is associated with an INSERT, UPDATE or DELETE statement. Whenever a DML statement is invoked, an implicit cursor is automatically made by Oracle if there is no explicit cursor available.
4. Which of the following implicit cursor returns true if an INSERT, UPDATE or DELETE statement affects one or more rows?
a) %FOUND
b) %NOTFOUND
c) %ISOPEN
d) %ROWCOUNT
View Answer
Explanation: %FOUND is the implicit cursor that returns true if an INSERT, UPDATE or DELETE statement affects one or more rows. It also returns true if a SELECT INTO statement returns one or more rows. In all other cases it returns false.
5. Which of the following implicit cursor returns the count of rows affected by an INSERT, UPDATE or DELETE statement?
a) %FOUND
b) %NOTFOUND
c) %ISOPEN
d) %ROWCOUNT
View Answer
Explanation: %ROWCOUNT is the implicit cursor that returns the count of rows affected by an INSERT, UPDATE or DELETE statement. It also returns the number of rows returned by a SELECT INTO statement.
6. Which of the following is the correct syntax to access a SQL cursor attribute?
a) select%attribute_name
b) oracle%attribute_name
c) sql%attribute_name
d) %attribute_name
View Answer
Explanation: The correct syntax to access a SQL cursor attribute is – sql%attribute_name. The attribute name is preceded by a % sign and SQL. For example – SQL%ROWCOUNT.
7. Which of the following is the correct syntax for creating an explicit cursor?
a) cursor_name IS column_name;
b) CURSOR cursor_name IS SELECT_statement;
c) cursor_name CURSOR IS SELECT_statement;
d) CURSOR cursor_name IS column_name;
View Answer
Explanation: The correct syntax for creating an explicit cursor is –
CURSOR cursor_name IS SELECT_statement;
Here, CURSOR and IS are keywords.
cursor_name is the name of the cursor that the user wants to put.
SELECT_statement is a simple select statement which tells us the columns and the table that has been used by the cursor. For Example –
CURSOR mycursor IS SELECT id, name, rollno FROM students;
8. How many steps are associated when working with an explicit cursor?
a) 3
b) 4
c) 5
d) 6
View Answer
Explanation: There are 4 steps associated when working with an explicit cursor. They are –
Declaring the cursor, Opening the cursor, Fetching the cursor and Closing the cursor.
9. Which of the following is the correct syntax to FETCH the cursor in PL/SQL?
a) FETCH cursor_name INTO variable_list;
b) FETCH cursor_name IN variable_list;
c) FETCH cursor_name AS variable_list;
d) FETCH cursor_name variable_list;
View Answer
Explanation: The correct syntax to FETCH the cursor in PL/SQL is –
FETCH cursor_name INTO variable_list;
Here, cursor_name is the name of the cursor.
variable_list is the list of variables in which you want to store the cursor result set.
10. Which of the following action is used with an explicit cursor to clears the active set of rows and frees the memory area used for the cursor?
a) DECLARE
b) OPEN
c) FETCH
d) CLOSE
View Answer
Explanation: Closing the cursor clears the active set of rows and frees the memory area used by the cursor. Its syntax is –
CLOSE cursor_name
Sanfoundry Global Education & Learning Series – PL/SQL.
To practice all areas of PL/SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.