0

I need to use REGEX (or similar functiuonality) to update an existing table in order to identify if a string field contains a correctly formatted code:

UPDATE tblRequests SET flagIsRefCodeOK=(RefCode REGEX '^[A-Z0-9]{8}-(?:[A-Z0-9]{4}-){3}[A-Z0-9]{12}$') WHERE DataSetID=11

But it doesn't seem to like the statement:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REGEX '^[A-Z0-9]

Note, this code will be added to a BEFORE INSERT trigger, which is responsible for updating a number of flags. I'm not fussed (much) with whether the REGEX is correct, especially within MySQL, I just want it to try to work. Then I'll figure out the exact REGEX if this doesn't work.

Thnx

3
  • This makes no sense. "Update in order to indentify" Wha..? Commented Jul 30, 2014 at 11:55
  • REGEXP returns just 0 or 1, nothing else. Commented Jul 30, 2014 at 11:56
  • @Strawberry apologies, I was replacing certain names for privacy, the first RefCode is a flag, I've now updated the example. Will check the other comments and update once I've tried. Commented Jul 30, 2014 at 12:00

1 Answer 1

1

The operator name is REGEXP not REGEX, so try:

UPDATE tblRequests
    SET flagIsRefCodeOK= (RefCode REGEXP '^[A-Z0-9]{8}-(?:[A-Z0-9]{4}-){3}[A-Z0-9]{12}$')
    WHERE DataSetID=11;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.