Standard Error Handling
Go Up to Error Handling and Recovery
Every time a SQL statement is executed, it returns a status indicator in the SQLCODE variable, which is declared automatically for SQL programs during preprocessing with gpre. The following table summarizes possible SQLCODE values and their meanings:
| Value | Meaning |
|---|---|
|
0 |
Success |
|
1–99 |
Warning or informational message |
|
100 |
End of file (no more data) |
|
< 0 |
Error. Statement failed to complete |
To trap and respond to run-time errors, SQLCODE should be checked after each SQL operation. There are three ways to examine SQLCODE and respond to errors:
- Use
WHENEVERstatements to automate checkingSQLCODEand handle errors when they occur. - Test
SQLCODEdirectly after individual SQL statements. - Use a judicious combination of
WHENEVERstatements and direct testing.
Each method has advantages and disadvantages, described fully in the remainder of this chapter.