1. What is a cursor in Oracle?
A cursor is a pointer that lets you access and process rows returned by a query
one by one.
2. Why do we need a cursor?
We need a cursor to handle query results row by row instead of all at once.
3. What does opening a cursor do?
Opening a cursor executes the query and prepares the result set for fetching.
4. What does fetching from a cursor
mean?
Fetching means retrieving the next row of data from the cursor into variables.
5. What does closing a cursor do?
Closing a cursor releases the memory and resources used by it.
6. Can we process multiple rows
without a cursor?
Yes, using SQL statements directly, but cursors help when we need row-by-row
processing.
7. What is a cursor variable?
It is a pointer variable that can hold a reference to a cursor result set.
8. What is the context area in
cursors?
It is a memory area where Oracle stores the query and the rows temporarily.
9. What happens if we forget to
close a cursor?
It can cause memory leaks and reduce performance.
10. Can we fetch rows in any order?
No, rows are fetched in the order returned by the query.
11. What is the difference between implicit and explicit cursors?
Implicit cursors are automatically created for simple queries; explicit cursors
are created by the programmer for more control.
12.Can a cursor return zero rows?
Yes, a cursor can return zero, one, or many rows.
13. How do we know if a cursor has fetched all rows?
By checking a status flag, like %NOTFOUND, which tells if there are no more
rows.
14. Can we use cursors in PL/SQL loops?
Yes, cursors are often used inside loops to process each row.
15. Can a cursor be passed between procedures?
Yes, using cursor variables or parameters.
16. Does using a cursor slow down performance?
It can be slower than set-based SQL if used unnecessarily because it processes
rows one by one.
17. Can we update data using a cursor?
Yes, some cursors allow updating or deleting rows while processing.
18. How many cursors can be open at once?
It depends on database limits, but you should close cursors to free resources.
19. Can cursors be used in triggers?
Yes, but they should be used carefully to avoid performance issues.
20. Are cursors only for SELECT statements?
Mostly yes, but some can also be used to fetch and manipulate rows in DML
operations.
No comments:
Post a Comment