mysql – How to check the occurrence of a string on a line and get x characters to its left and y to its right?

Question:

I have a problem with a MySQL query and I'm looking for help. Suppose I have many rows in the PROCESSES column and one of them looks like this:

IBAMAPROCUR: DF00025372 ADRIANA MAIA VENTURINIAPDO: JOSE DOS

I want to check if there are 25372 characters on that line, if there is, I want to get 10 characters before the location and 10 after. And check if in this range there is the acronym DF. If it exists, show the line. This way I would be sure that this is an Attorney OAB number. Would someone give me a helping hand to mount a select for this?

Answer:

Hi.

A common select with where doesn't work for you?

SELECT Name, Processes FROM (Table) WHERE Processes LIKE '%df%' AND Processes LIKE '%25372%'

Scroll to Top