On this page
ON ERROR
Core command
In a Script, stops at the first failed statement (STOP) or continues (CONTINUE, the default).
Syntax
ON ERROR STOP|CONTINUE
Arguments
| Argument | Required | Values | Default |
|---|---|---|---|
STOP or CONTINUE | Yes | STOP ends the Script at the first failure; CONTINUE runs the next statement | CONTINUE at the start of every Script |
Examples
ON ERROR STOP;
ON ERROR CONTINUE;
Example session
ERROR: Script stop.bsql stopped by ON ERROR STOP at statement 3 (line 3)
stop.bsql: FAILED (3 statements, 1 failed) [run NSM038PL], stopped at statement 3 (line 3)
Details
STOP and CONTINUE
ON ERROR is allowed in Scripts only. At the prompt, a line of several statements already stops at its first failure.
CONTINUE, the setting every Script run starts with: a failed statement is reported and counted, and the next statement runs.STOP: the first failed statement ends the Script. Nothing after it runs, a message names the statement and its line, and the Script's status isFAILED.
A Script called by this Script starts with the same setting; a change made inside it ends when it returns.
Transactions
A failed SQL statement rolls back the pending transaction, as it always did: with autocommit off, earlier uncommitted changes are lost too, and a warning says so. ON ERROR STOP itself never commits or rolls back.
Related
Used in these how-tos
- How do I run a post-deployment smoke check on every environment?
- How do I write a report Script that stops at the first failure?
Last modified in release 5.5.0.
Found something wrong or unclear on this page? Tell us, with the page address.