0

I'm attempting what I thought was a pretty straight-forward SQL statement. I'm trying to use a REGEX expression to only grab records that have a name consisting of only 3 numbers.

However, I'm getting an error and I can't figure out why. Because it's DB2, there aren't nearly as many examples to draw from (as there would be with Postgres, for example), so I'm stuck.

Can anyone see what's wrong?

SELECT
    ia.ID
   ,ia.DESCRIPTION
FROM INVENTORY.ACTIVITIES ia
WHERE
     REGEXP_LIKE(ia.NAME, '[0-9]{3}')

Error:

[IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token ")" was found following "(ia.NAME,'[0-9]{3}')". Expected tokens may include: "<interval_qualifier>". SQLSTATE=42601.

mustaccio
  • 18,234
  • 16
  • 48
  • 57
Dan
  • 4,197
  • 6
  • 34
  • 52

1 Answers1

1

Your code should compile. It doesn't do what you want though. You need markers for the beginning and end of the string:

SELECT ia.ID, ia.DESCRIPTION
FROM INVENTORY.ACTIVITIES ia
WHERE REGEXP_LIKE(ia.NAME, '^[0-9]{3}$')

My best guess for your error is a hidden character.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786