How to split a single row in to multiple columns in mysql

前端 未结 5 1294
轻奢々
轻奢々 2021-01-16 08:50

Simply Asking, Is there any function available in mysql to split single row elements in to multiple columns ? I have a table row with the fields, user_id, user_name, u

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 09:16

    this should do it

    DELIMITER $$
    
    DROP PROCEDURE IF EXISTS `CSV2LST`$$
    
    CREATE DEFINER=`root`@`%` PROCEDURE `CSV2LST`(IN csv_ TEXT)
    BEGIN
    
     SET @s=CONCAT('select \"',REPLACE(csv_,',','\" union select \"'),'\";');
     PREPARE stmt FROM @s;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt; 
    END$$
    
    DELIMITER ;
    

提交回复
热议问题