← All errors

SQLCODE -138

SQL0138 Argument of substring function not valid

IBM message text
Argument &1 of substringing function not valid.
SQLCODE
-138
SQLSTATE
22011

Most common cause

SUBSTR (or LEFT, or OVERLAY) with a start position or length beyond the string's length, or an argument that is not an integer.

Other causes

  • A position computed with LOCATE, which returns 0.

How to fix it

Check lengths with LENGTH, or use LEFT and RIGHT when they are enough. Guard the calculation with a CASE when the position can be 0.

Related errors

Text and codes from IBM documentation for 7.6. Checked on .