---
title: "DB2 Cursors Tricky interview Question"
description: "Tricky interview questions to read for interviews on DB2 cursors."
url: https://srinimf.com/2015/10/23/db2-cursors-tricky-interview-question/
date: 2015-10-23
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/10/tricky-db2-cursor-questions.jpg?fit=1200%2C900&ssl=1
categories: ["DB2", "DB2 V11"]
tags: ["DB2 Cursor tricky interview Question", "DB2 Cursors"]
type: post
lang: en
---

# DB2 Cursors Tricky interview Question

Q) Can we open the same cursor multiple times, when you use more than one DB2 subsystem ?

A) The answer is ‘Yes”. Many programmers said ‘No’ to this question. But this is a [tricky interview question](https://srinimf.com/2020/05/17/sql-views-present-after-modifying-table/). Recently my friend faced same question.

Related[How to Resolve SQL Error -500 Quickly](https://srinimf.com/2015/12/05/sql-error-500-cursor-was-closed-when-the-connection-destroyed/)

Usually, same cursor can be opened only one time in a program, and Fetch will be in a loop to retrieve rows one by one. Let us see, in which scenario this kind of question comes. When you use multiple DB2 subsystems in a program, then, you can open same cursor multiple times, then you will not get SQL error code like OPENed a Cursor, which is already opened.

Related[DB2: How to Fix Cursor Open Error Quickly](https://srinimf.com/2015/10/11/db2-open-cursor-unsuccessful-probable-reasons/)

```
DECLARE C CURSOR FOR ...
CONNECT TO X
OPEN C
FETCH C INTO ...
CONNECT TO Y
OPEN C
FETCH C INTO ..
```

Related[COBOL Tricky Interview Question: Processing of 2 Files](https://srinimf.com/2014/08/05/cobol-tricky-interview-question/)

Here, first time you are connecting to ‘X’ instance. Second time you are connecting to instance ‘Y’. The same is applicable in a Single locations and packages are in different collections.

**Warning:** When your program is using only one sub-system, then, if you open a cursor more than once, you will get SQL error.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2015%2F10%2F23%2Fdb2-cursors-tricky-interview-question%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F10%2Ftricky-db2-cursor-questions.jpg%3Ffit%3D1200%252C900%26ssl%3D1&description=DB2%20Cursors%20Tricky%20interview%20Question)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/10/23/db2-cursors-tricky-interview-question/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/10/23/db2-cursors-tricky-interview-question/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/10/23/db2-cursors-tricky-interview-question/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/10/23/db2-cursors-tricky-interview-question/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20DB2%20Cursors%20Tricky%20interview%20Question&body=https%3A%2F%2Fsrinimf.com%2F2015%2F10%2F23%2Fdb2-cursors-tricky-interview-question%2F&share=email)
-

### Like this:

Like Loading…