DB2 Scalar functions - REGEXP_SUBSTR
The REGEXP_SUBSTR scalar function returns one occurrence of a substring of a string that matches the regular expression pattern.
The schema is SYSIBM.
If the string unit is specified as CODEUNITS16 or OCTETS, and if the string unit of the source string is CODEUNITS32, an error is returned (SQLSTATE 428GC).
For more information, see "String units in built-in functions" in Character strings.
The result of the function is a string. The data type of the string is the same data type as the source string, except for CHAR, which becomes VARCHAR; and GRAPHIC, which becomes and VARGRAPHIC. The length attribute of the result data type is same as the length attribute of the source string. The actual length of the result is the length of the occurrence in the string that matches the pattern expression. If the pattern expression is not found, the result is the null value.
The result of the REGEXP_SUBSTR function can be null. If any argument is null, the result is the null value.
SELECT REGEXP_SUBSTR('hello to you', '.o',1,1) FROM SYSIBM.SYSDUMMY1
SELECT REGEXP_SUBSTR('hello to you', '.o',1,2) FROM SYSIBM.SYSDUMMY1
SELECT REGEXP_SUBSTR('hello to you', '.o',1,3) FROM SYSIBM.SYSDUMMY1