Firebird Documentation IndexFirebird 2.1 Language Ref. UpdateExternal functions (UDFs) → substr
Firebird Home Firebird Home Prev: strlenFirebird Documentation IndexUp: External functions (UDFs)Next: substrlen

substr

Library: ib_udf

Changed in: 1.0, 1.5.2, 2.0

Description: Returns a string's substring from startpos to endpos, inclusively. Positions are 1-based. If endpos is past the end of the string, substr returns all the characters from startpos to the end of the string. This function only works correctly with single-byte characters.

Result type: VARCHAR(n)

Syntax (unchanged): 

substr (str, startpos, endpos)

Declaration: 

DECLARE EXTERNAL FUNCTION substr
   CSTRING(255) NULL, SMALLINT, SMALLINT
   RETURNS CSTRING(255) FREE_IT
   ENTRY_POINT 'IB_UDF_substr' 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

Although the function arguments are slightly different, consider using the internal SQL function SUBSTRING instead, for better compatibility and multi-byte character set support.

Prev: strlenFirebird Documentation IndexUp: External functions (UDFs)Next: substrlen
Firebird Documentation IndexFirebird 2.1 Language Ref. UpdateExternal functions (UDFs) → substr