Reputation: 9311
(Other than using a UDF) Any REGEXP-In-SQL support for DB2 9.7 ?
Upvotes: 13
Views: 53390
Reputation: 17118
Starting with DB2 11.1 there is built-in regex support. One of the new function is REGEXP_SUBSTR
and there are some more.
SELECT REGEXP_SUBSTR('hello to you', '.o',1,1)
FROM sysibm.sysdummy1
Upvotes: 9
Reputation: 148
There is no built-in support for regular expressions in DB2 9.7.
The only way is using UDFs or table functions as described in the article 'OMG Ponies' added in the comment.
@dan1111: I do not appreciate my post being edited, especially if people can't read the question correctly. The OP asked Any REGEXP-In-SQL support for DB2 9.7
SQL is not XQuery !!!
Sorry, don't delete the text of my 100% correct answer. You can add a comment or write your own answer.
Upvotes: 4
Reputation: 51
That works fine except for DB2 z/OS - in DB2 v10 z/OS you must use PASSING as follows
with val as (
select t.text
from texts t
where xmlcast(xmlquery('fn:matches($v,"^[A-Za-z 0-9]*$")'
PASSING t.text as "v" ) as integer) = 0
)
select * from val
Upvotes: 5
Reputation: 7693
The real answer is that DB2 does support regular expression since PureXML was added (v9.7 included) via xQuery with the matches function.
For example:
db2 "with val as (
select t.text
from texts t
where xmlcast(xmlquery('fn:matches(\$TEXT,''^[A-Za-z 0-9]*$'')') as integer) = 0
)
select * from val"
For more information:
Upvotes: 6
Reputation: 71
I'm komikoni(Keisuke Konishi).
I created the regular expression function (UDF) which does not exist in db2. The UDF using the SQL/XML(Xquery). You can easily install.
List of regular expressions provide UDF
Scripts can be downloaded from here. (Sorry in Japanese)
https://www.ibm.com/developerworks/jp/data/library/db2/j_d-regularexpression/
(English : Machine translation Script : The last of a Japanese page)
I look forward to your feedback and comments.
Upvotes: 7