Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8427855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:53:36+00:00 2026-06-10T04:53:36+00:00

I have a table that stores some comma separated strings. Is there a way

  • 0

I have a table that stores some comma separated strings. Is there a way to write a sql to
return me a separate rows for each token string obtained by splitting across commas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:53:37+00:00Added an answer on June 10, 2026 at 4:53 am

    You can simply write and call a stored procedure

    DELIMITER $$
    
    DROP PROCEDURE IF EXISTS explode_table $$
    CREATE PROCEDURE explode_table(bound VARCHAR(255))
    
      BEGIN
    
        DECLARE id INT DEFAULT 0;
        DECLARE value TEXT;
        DECLARE occurance INT DEFAULT 0;
        DECLARE i INT DEFAULT 0;
        DECLARE splitted_value INT;
        DECLARE done INT DEFAULT 0;
        DECLARE cur1 CURSOR FOR SELECT table1.id, table1.value
                                             FROM table1
                                             WHERE table1.value != '';
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
    
        DROP TEMPORARY TABLE IF EXISTS table2;
        CREATE TEMPORARY TABLE table2(
        `id` INT NOT NULL,
        `value` VARCHAR(255) NOT NULL
        ) ENGINE=Memory;
    
        OPEN cur1;
          read_loop: LOOP
            FETCH cur1 INTO id, value;
            IF done THEN
              LEAVE read_loop;
            END IF;
    
            SET occurance = (SELECT LENGTH(value)
                                     - LENGTH(REPLACE(value, bound, ''))
                                     +1);
            SET i=1;
            WHILE i <= occurance DO
              SET splitted_value =
              (SELECT REPLACE(SUBSTRING(SUBSTRING_INDEX(value, bound, i),
              LENGTH(SUBSTRING_INDEX(value, bound, i - 1)) + 1), ',', ''));
    
              INSERT INTO table2 VALUES (id, splitted_value);
              SET i = i + 1;
    
            END WHILE;
          END LOOP;
    
          SELECT * FROM table2;
        CLOSE cur1;
      END; $$
    -------------------
    CALL explode_table(',');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table from a vendor application that stores some xml data into
I have a table that stores various clients I have done work for, separated
In SQL Server, I have a table where a column A stores some data.
I have a mysql database that stores some timestamps. Let's assume that all there
I have a database that stores components in a component table. There is a
I have a table that stores data that has been entered regarding the amount
I have a table that stores email in 3 diffrent columns name host and
I have a table that stores user information. The table has a userid (identity)
I have a table that stores employee names and years they worked. The columns
I have mysql table that has a column that stores xml as a string.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.