Firebird Documentation IndexFirebird 2.0 Language Ref. UpdateExternal functions (UDFs) → substrlen
Firebird Home Firebird Home Prev: substrFirebird Documentation IndexUp: External functions (UDFs)Next: truncate, i64truncate

substrlen

Library: ib_udf

Added in: 1.0

Changed in: 1.5.2, 2.0

Better alternative: Internal function SUBSTRING()

Description: Returns the substring starting at startpos and having length characters (or less, if the end of the string is reached first). Positions are 1-based. If either startpos or length is smaller than 1, an empty string is returned. This function only works correctly with single-byte characters.

Result type: VARCHAR(n)

Syntax: 

substrlen (str, startpos, length)

Declaration: 

DECLARE EXTERNAL FUNCTION substrlen
   CSTRING(255) NULL, SMALLINT, SMALLINT
   RETURNS CSTRING(255) FREE_IT
   ENTRY_POINT 'IB_UDF_substrlen' MODULE_NAME 'ib_udf'

The above declaration is from the file ib_udf2.sql. The NULL after the argument is an optional addition that became available in Firebird 2. If the argument is declared with the NULL keyword, the engine will pass a NULL argument value unchanged to the function. This leads to a NULL result, which is correct. Without the NULL keyword (your only option in pre-2.0 versions), NULL is passed to the function as an empty string and the result is an empty string as well.

For more information about passing NULLs to UDFs, see the note at the end of this book.

Notes: 

Tip

Firebird 1.0 has also implemented the internal SQL function SUBSTRING, effectively rendering substrlen obsolete in the same version in which it was introduced. SUBSTRING also supports multi-byte character sets. In new code, use SUBSTRING.

Prev: substrFirebird Documentation IndexUp: External functions (UDFs)Next: truncate, i64truncate
Firebird Documentation IndexFirebird 2.0 Language Ref. UpdateExternal functions (UDFs) → substrlen