regex - Using Regexp in MySQL. Will it give an occurrence count? -
I have a VARCHAR (InnoDB table) and I want to count how many examples of strings [# ##] Or [## af] can be in the field in each line (to indicate that the placeholder for the integer, and the air force shows that a letter can be present from one letter to the limit). Regex
\ [[0-9] + \] | \ [[0-9] + [AK] \]
If a match is returned then returns 1, but I have not yet given the information whether the match within each record There is a possibility to return to the Reykjax. Is this possible?
Ideally I want the result:
Ozid | Text | Item_ count ------------------------------- 1 & lt; Blah & gt; 7 2 & lt; Blah & gt; 2 3 & lt; Blah & gt; 1 4 & lt; Blah & gt; 0 5 & lt; Blah & gt; 10
I do not know what the limitations or constraints of regex in MySQL can be in this regard. If this can only be done programmatically, then I would like to use a stored procedure to put it in the database context.
Please note that my question is not about solving the problem only, it is especially about the use of regex.
I am curious about other databases - there may be special solutions, but I have been very curious about what I am asking for regexp to do here.
MySQL does not offer functionality to you My first comment is that you have a list of code in a column in your column. This is a poor data design. You must have a consortium / junction table for this.
There is a way to count the incidence of fixed string in another string using replace ()
. MySQL does not provide regex_replace ()
(although you can possibly get the code for Google and MySQL versions) Your codes are very simple, so with an unusual creation, you solve the problem can do. Calculates the number of '[999]'
in the following string: Select
(length (copy, '[999]', '[99 9] One ') - length (color))
You can repeat it only for N code:
select ((length (copy,' [999] A ') - Length (cola) + (length (cola,' [99A] ',' [99 A] A ')) - Length (cola)) .
If you know what appears in each code (length (chain, '[99f]', '[99f] a')) - length (cola)) most Once more, you can change it with some simple comparison: Choose
('% [999]%' like 'curl'% [99a]% '+ +. Like '% [99f]%')
Let me re-emphasize that storing columns as a list in a column is a bad idea. If your column is doing this, then you should create an association table, which will make it easy to do special queries.
Comments
Post a Comment