- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain the scenario in which CURSOR should be used over a standalone SELECT statement?
The standalone SELECT statement is generally used when we use a primary or an alternate key in the WHERE clause. Therefore, In this case we are certain that the standalone select statement will return only one row since the primary key cannot have a duplicate value (multiple rows).
If we want to query the database using a non-unique key which could return multiple rows from a DB2 table, we have to use a cursor to handle the multiple rows returned. We can access the cursor in a loop to read each row data one by one.
For example, if we want to extract all the orders which were placed on 2020-07-28 from the ORDERS table, we have to use a cursor as there can be multiple orders in a particular date.
Advertisements