Thread: DB2

What is a cursor? Why not just SELECT into variables?

Started by Jordan • user2 replies186 viewsLast activity 2 weeks ago
Post #1
0 votes
Jordan
Reputation
12
Posts: 32
Joined: May 2, 2026, 11:10 AM
Posted: Jul 30, 2026, 1:51 PM

Single-row SELECT INTO makes sense. For many rows people say DECLARE CURSOR / OPEN / FETCH / CLOSE.

Is a cursor just a pointer walking the result set?

Post #2
1 votes
Omar
Reputation
155
Posts: 12
Joined: Jan 7, 2025, 10:05 AM
Posted: Jul 30, 2026, 3:51 PM

Yeah. SELECT INTO expects one row (or you handle -811). Cursor is how batch COBOL walks many rows: OPEN, FETCH until SQLCODE 100, CLOSE.

Remember to check SQLCODE on each FETCH.

You must be signed in to reply to this thread