Search code examples
db2ibm-midrangedb2-400

REGEXP_LIKE in DB2 v7r1 (7.1?)


From,

https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/db2/rbafzregexp_like.htm

SELECT PID FROM PRODUCT 
 WHERE NOT REGEXP_LIKE(pid,'[0-9]{3}-[0-9]{3}-[0-9]{2}')

But when I run a similar command,

SELECT MYCOLUMN FROM MYTABLE 
 WHERE NOT REGEXP_LIKE(MYCOLUMN,'[0-9]{3}-[0-9]{3}-[0-9]{2}')

I get

SQL State: 42601 Vendor Code: -104 Message: [SQL0104] Token was not valid. Valid tokens: < > = <> <= !< !> !=

= ¬< ¬> ¬= IN. Cause . . . . . : A syntax error was detected at token . Token is not a valid token. A partial list of valid tokens is < > = <> <= !< !> != >= ¬< ¬> ¬= IN. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token . Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is , correct the SQL statement because it does not end with a valid clause.

Is there any reason why this example does not work? Is IBM v7r1 not the same as 7.1?


Solution

  • 7.1 and v7r1 are the same thing...

    The regular expression support was added as part of technology refresh (TR) level 9

    From a command line, use the Work with PTF Groups (WRKPTFGRP) command

    WRKPTFGRP PTFGRP(SF99707) PTFGRPLVL(*INSTALLED)
    

    Also, you need to have 5770-SS1 Option #39 International Components for Unicode insallted. You can use the Display Software Resources (DSPSFWRSC) to check for that.

    If that's not installed, you'd see a message:
    SQL0204 - QQQSVREG in QSYS type *SRVPGM not found.