Db2 SQLCODE

SQLCODE -723: Error in a triggered SQL statement

SQLCODE -723 (SQLSTATE 09000) means an SQL statement inside a trigger failed. The message carries the trigger name and the real SQLCODE, SQLSTATE and tokens of the statement that failed, so you fix -723 by fixing that inner error.

Other names for this code

Also written as SQL -723, SQLCODE=-723, SQLCODE = -723, db2 -723, sqlstate 09000, SQL0723N, an error occurred in a triggered SQL statement.

What it means

A trigger runs its own SQL when an INSERT, UPDATE, DELETE or MERGE fires it. If one of those statements fails, the program doesn't see the original error directly. It sees -723, with the original error packed into the message.

  • Trigger name is the trigger that was running.
  • SQLCODE and SQLSTATE are the real error from the failing statement inside the trigger.
  • Message tokens are the tokens of that inner error. The list can be cut short.
  • Section number says which statement in the trigger failed. If the trigger has a WHEN clause, that is section 1. The triggered statements are numbered from 2, whether or not there is a WHEN clause.

Nothing is changed. The trigger's work and the statement that fired it are both undone, and the triggering table is left as it was.

Common causes

  • The trigger inserts into an audit or history table and hits a duplicate key, -803. A key built from a timestamp or the business key alone often clashes when two changes land together.
  • The trigger writes a value that breaks a constraint on another table, such as -530 for a missing parent or -545 for a check constraint.
  • A value the trigger builds is too long for the target column.
  • The trigger's package lacks a privilege on a table it uses, -551.
  • A table the trigger uses is unavailable, -904, or the trigger hit a deadlock or timeout.

How to find the problem

  1. Read the inner SQLCODE and tokens in the -723 message and look that code up. That is the real error.
  2. Find the failing statement from the trigger name and section number. Db2 stores trigger statements in the trigger's package, so SELECT SEQNO, STMT FROM SYSIBM.SYSPACKSTMT WHERE COLLID = 'PAYROLL' AND NAME = 'EMPAUDT1' AND SECTNOI = 2 ORDER BY SEQNO returns it. COLLID is the trigger's schema.
  3. The statement text there is stored in Unicode for triggers created in Db2 Version 8 new-function mode or later. If you browse it in SPUFI, use DISPLAY UTF8 in ISPF browse to read it.
  4. SYSIBM.SYSTRIGGERS holds the full trigger definition if you'd rather read the whole thing.

How to fix it

  • Fix the inner error as you would anywhere else, following the page for that SQLCODE.
  • For duplicate keys in audit tables, add a column that keeps keys unique, such as a timestamp with full precision or a sequence value.
  • For privilege errors, grant what the trigger's package needs.
  • Make the program log the full SQLERRMC for -723, so the inner code isn't lost.

IBM documentation

IBM documentation: -723. Use the documentation for your installed release.

Report a correction to WND Software.

Questions

Why does my program get -723 instead of the real error?

Errors inside a trigger are always wrapped in -723. The real SQLCODE and SQLSTATE are in the message tokens, in SQLERRMC.

Does -723 leave partial changes behind?

No. The triggered statements and the statement that fired the trigger are both undone, and the table is unchanged.

Is -723 the same on Db2 for LUW?

Yes. Db2 for LUW reports SQL0723N with SQLSTATE 09000 and includes the inner error in the message.