Skip to Main Content
IBM Data and AI Ideas Portal for Customers


This portal is to open public enhancement requests against products and services offered by the IBM Data & AI organization. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:


Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,


Post your ideas

Post ideas and requests to enhance a product or service. Take a look at ideas others have posted and upvote them if they matter to you,

  1. Post an idea

  2. Upvote ideas that matter most to you

  3. Get feedback from the IBM team to refine your idea


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

IBM Employees should enter Ideas at https://ideas.ibm.com


Status Not under consideration
Workspace Db2 for z/OS
Created by Guest
Created on Nov 13, 2015

Regular Expressions (regex) scalar function

The XMLQUERY function allows the user to use the 'fn:matches' XQuery function, which is great. Please see example UDF which does this...

~~~~~~~~~~
--#SET TERMINATOR !

CREATE FUNCTION "UDF_STRING_REGEX_MATCH"
( SEARCHSTRING VARCHAR (50)
)
RETURNS SMALLINT

DETERMINISTIC
NO EXTERNAL ACTION

BEGIN

DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INTEGER DEFAULT 0;

DECLARE REGEX_RESULT SMALLINT DEFAULT 0;
DECLARE XMLDOC VARCHAR(60); -- 50 FOR DATA, 10 FOR XML TAGS

SET XMLDOC = '' || TRIM(SEARCHSTRING) || '' ;

-- Can't seem to get it to work using a variable for the fn:matches parm,
-- so this is what I have to do instead (hard coded regular expression)
-- which means I have to have many different such statements in my code
-- to cater for my various possible regular expressions - not good

SELECT 1
INTO REGEX_RESULT
FROM SYSIBM.SYSDUMMY1
WHERE XMLCAST(
XMLQUERY('fn:matches($D/DOC, "^1[0-9][0-9]")'
PASSING XMLPARSE(DOCUMENT XMLDOC) AS "D") AS INTEGER) = 1;

RETURN REGEX_RESULT ;

END!
~~~~~~~~~~~~~~~~~~~~~~

When I execute this, passing in a value of 123 as the input parameter, I get the expected result of 1 back because 123 matches the literal regular expression within the UDF. I see from this manual (http://www-01.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.xml/src/tpc/db2z_fnmatches.dita ) that the “pattern is string literal”. The same is also true in DB2 z/OS Version 11.

This RFE is to request that 'pattern' be changed to allow for a VARIABLE or a literal, because allowing a literal only makes for a UDF which is not very generic. In order to be able to handle a number of desired regex patterns I would need to hard code a series of similar statements and conditionally execute the right one based on some other input variable. Even then of course, it would still require further coding changes to add more expressions in the future. It would be far easier (better?) if I could pass the regex expression into the UDF and use that variable as 'pattern'.

Better still would be a scalar function that allows for a REGEX match on a string using a pattern, without having to build an XMLDOC etc.

Thanks