'can i make an insert stored procedure with substring_index in mysql?

I have a problem with existing data on a wordpress page, there is a form created in contact-form-7 that saves multiple member data in a single field.

In MySql database there are cells with multiple data and with a simple query with substring_index and the '\n' parameter I can see in separate rows. But when performing a stored procedure to copy this data correctly and be able to work with it, it generates a creation error #1064 (something is wrong in the query)

For example, in one registry I have 3 names, in others 8 and sometimes only one.

name1
name2
name3

I make this procedure to extract the data but I don't understand where is the problem.

CREATE PROCEDURE sp_creaCopiaRegistroIntegrante(IN `id_cartel` INT(11))

INSERT into integrantes ( nombre, apellido, email,
        rasgo, escuela, vinculo, pais,
        ciudad, update_date, creation_date, masuno,id_cartel)
    select
        SUBSTRING_INDEX(t1.value, '\n', 9), -- nombre
        SUBSTRING_INDEX(t2.value, '\n', 9), -- apellido
        SUBSTRING_INDEX(t3.value, '\n', 9), -- email
        SUBSTRING_INDEX(t4.value, '\n', 9), -- rasgo
        '', -- escuela solo aplica para el caso de masuno -- escuela
        '', -- vinculo solo aplica para el caso de masuno -- vinculo
        SUBSTRING_INDEX(t5.value, '\n', 9), -- pais
        SUBSTRING_INDEX(t6.value, '\n', 9), -- ciudad
        CURRENT_TIMESTAMP(), -- update_date
        CURRENT_TIMESTAMP(), -- creation_date
        '0' as masuno, -- masuno
        t1.data_id -- id_cartel
        from
            `zkd_cf7_vdata_entry` as t1
            INNER JOIN `zkd_cf7_vdata_entry` as t2 on t1.data_id=t2.data_id
            INNER JOIN `zkd_cf7_vdata_entry` as t3 on t1.data_id=t3.data_id
            INNER JOIN `zkd_cf7_vdata_entry` as t4 on t1.data_id=t4.data_id
            INNER JOIN `zkd_cf7_vdata_entry` as t5 on t1.data_id=t5.data_id
            INNER JOIN `zkd_cf7_vdata_entry` as t6 on t1.data_id=t6.data_id
        WHERE
            t1.data_id = @p0 AND -- id del formulario
            t1.name = 'Nombre' and -- nombre integrante
            t2.name = 'Apellido' and -- apellido integrante
            t3.name = 'email' and -- email integrante
            t4.name = 'Rasgo' and -- rasgo integrante
            t5.name = 'pais' and -- pais integrante
            t6.name = 'ciudad' -- ciudad integrante

when I execute the stored procedure: SET @p0='5'; CALL sp_creaCopiaRegistroIntegrante(@p0);

This is the result: result of the query

So, my question is how to make that become 3 separate records when I execute the insert function?

I really appreciate any help or guidance on what to do in this case.

Greetings



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source