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

ArgumentRequiredValuesDefault
STOP or CONTINUEYesSTOP ends the Script at the first failure; CONTINUE runs the next statementCONTINUE 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)
A Script stopped by ON ERROR STOP

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 is FAILED.

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.

Used in these how-tos

Last modified in release 5.5.0.

Found something wrong or unclear on this page? , with the page address.