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.

Updated on: 14-Sep-2020

55 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements