A
A
Anton Kokarev2020-06-15 16:42:49
MySQL
Anton Kokarev, 2020-06-15 16:42:49

How to set a MAC address lookup pattern in SQL?

In the Tickets table, the text is written in free form in the Comment field. Among other things, MAC addresses are written in free form in this text. It is necessary to find all lines containing the wanted MAC.
Text examples:

Купили роутер f8f02804213e оплата нал
Замена роутера по гарантии. Старый 28:28:00:42:11:AA новый AA:BB:CC:55:66:77
Установлен пон D345.00ff.41ED
Купили ротер 28:28:00:55:66:77

the query %28%28%00%55%66%77%finds not only 4 examples, but also 2.
% is any number of any characters, and I need 1, but not as a mandatory one, but as a possible one.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2020-06-15
@akokarev

SELECT * FROM tickets 
WHERE UPPER( REPLACE( REPLACE( REPLACE( text, '.', '' ), ':', '' ), '-', '' )) LIKE '%282800556677%'

falling under a condition something like "serial number 1F2828004211AA0065400121"
In such cases, the delimiter is used:
SELECT * FROM tickets 
  WHERE CONCAT(' ', UPPER( REPLACE( REPLACE( REPLACE( text, '.', '' ), ':', '' ), '-', '' )) , ' ')
       LIKE '% 282800556677 %'

A
Anton Kokarev, 2020-06-15
@akokarev

SELECT * FROM tickets t WHERE t.text REGEXP '([0-9A-Fa-f]{2}[.:-]?){5}([0-9A-Fa-f]{2})'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question