How to smooth table function results in MySQL?

I am using MySQL and I have a function that will take col data from a table row and return a table function. For example, a function like this:

CREATE FUNCTION [dbo].[wordlongerthan4](
 @input text
) returns @result table(
 pos int,
 word varchar,
)

which will return a word longer than 4char and its position.

I want to make sql something like below

select t.name,wordlongerthan4(t.content) from sometable as t;

in the table

------------------------------------------------------------------
| id       | name        | content                               |
------------------------------------------------------------------
|1         | my1         | i love something and nothing          |
|2         | my2         | It is a sunny day today               |

to get the result:

|name   | pos | word           |
--------------------------------
|my1    |8    |something       |
|my1    |22   |nothing         |
|my2    |9    |sunny           |
|my2    |20   |today           |

How can I write sql? (wordlongerthan4 function already exists, I only need sql!)

+4
source share
2 answers

What are you talking about:

  • Going through each record and retrieving content.
  • Separation of content into a separator (space, in this case).
  • Measuring the length of each piece
  • , < N (4).
  • .

ajreal, , , php/java/whatever.

/ , : explode() mysql.

0

(ab) JSON_TABLE MySQL 8, :

set @input = 'i love something and nothing';

SELECT Value, LENGTH(Value) as Length, LOCATE(Value, @delimited) as pos
     FROM
       JSON_TABLE(
         CONCAT('["', REPLACE(@delimited, ' ', '", "'), '"]'),
         "$[*]"
         COLUMNS(
           Value varchar(50) PATH "$"
         )
       ) data
where LENGTH(Value) > 4;
0

Source: https://habr.com/ru/post/1583910/


All Articles