I'm trying to understand some COBOL
code and I'm unsure about what happens when a FETCH INTO
is performed and the query returns no results. So, for example, if I have an integer column but my query returns no rows and I'm fetching into an integer variable, what happens to that integer variable? Does it contain its original value or does it get set to zero? Something else?
Asked
Active
Viewed 153 times
0

Pete
- 6,585
- 5
- 43
- 69
-
1Why would it matter? Without a good sql return, you'd not use the data, would you? – Bill Woodger Feb 12 '15 at 21:47
-
2It would be an idea to show the code which is causing confusion. Also which DBMS and on which OS? I'll guess that you're looking at bad code, and may be getting the value which happened to be in the field at the time the SQL was run, – Bill Woodger Feb 13 '15 at 12:51
1 Answers
1
It might depend on the DBMS you are using. With DB2 your FETCH
would fail with SQLCODE=+100
and no value would be assigned to the given host-variable. But as @Bill Woodger already said in his comment: as you should handle the fetch-error anyway you best assume that the value is undefined.

piet.t
- 11,718
- 21
- 43
- 52