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 8046065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:42:08+00:00 2026-06-05T05:42:08+00:00

I have a non-normal field containing multiple values because it is Xml data that

  • 0

I have a non-normal field containing multiple values because it is Xml data that wasn’t intended to be queried, until now. Can MySQL split this xml column into multiple rows?

Table

NameA   |   <Xml><Values<Value>1</Value><Value>2</Value><Value>3</Value></Values></Xml>
NameB   |   <Xml><Values<Value>1</Value><Value>2</Value></Values></Xml>
NameC   |   <Xml><Values<Value>1</Value><Value>2</Value><Value>3</Value><Value>4</Value></Values></Xml>

I want

NameA   |   1
NameA   |   2
NameA   |   3
NameB   |   1

Like this MSSQL/TSQL solution

SELECT
    I.Name,
    Value.value('.','VARCHAR(30)') AS Value 
FROM
    Item AS I
CROSS APPLY
    Xml.nodes('/Xml/Values/Value') AS T(Value)
WHERE
    I.TypeID = 'A'

But in MySQL I can only get

NameA   |   123
NameB   |   12
NameC   |   1234

with

SELECT
    I.`Name`,
    ExtractValue(Xml,'/Xml/Values/Value') AS ListOfValues
FROM
    Item AS I
WHERE
    I.TypeID = 'A'
;

Are there any elegant ways to split xml in MySQL?

  • 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-05T05:42:10+00:00Added an answer on June 5, 2026 at 5:42 am

    No. You must solve this just like other mysql split column problems.

    • Can MySQL split a column?
    • Mysql string split

    I.e. Specifically based on this answer

    DROP FUNCTION IF EXISTS STRSPLIT;
    DELIMITER $$
    CREATE FUNCTION STRSPLIT($Str VARCHAR(20000), $delim VARCHAR(12), $pos INTEGER) 
        RETURNS VARCHAR(20000)
    BEGIN
        DECLARE output VARCHAR(20000);
    
        SET output = REPLACE(SUBSTRING(SUBSTRING_INDEX($Str, $delim, $pos)
                     , LENGTH(SUBSTRING_INDEX($Str, $delim, $pos - 1)) + 1)
                     , $delim
                     , '');
    
        IF output = '' 
            THEN SET output = null;
        END IF;
    
        RETURN output;
    END $$
    

    You can iterate through the values like so

    DROP PROCEDURE IF EXISTS GetNameValues $$
    CREATE PROCEDURE GetNameValues()
    BEGIN
        DECLARE i INTEGER;
    
        DROP TEMPORARY TABLE IF EXISTS TempList;
        CREATE TEMPORARY TABLE TempList(
            `Name` VARCHAR(256) COLLATE utf8_unicode_ci NOT NULL,
            `ValueList` VARCHAR(20000) COLLATE utf8_unicode_ci NOT NULL
        );
        DROP TEMPORARY TABLE IF EXISTS Result;
        CREATE TEMPORARY TABLE Result(
            `Name` VARCHAR(256) COLLATE utf8_unicode_ci NOT NULL,
            `Value` VARCHAR(128) COLLATE utf8_unicode_ci NOT NULL
        );
    
        INSERT INTO
            TempList
        SELECT
            I.`Name`,
            ExtractValue(Xml,'/Xml/Values/Value') AS ValueList
        FROM
            Item AS I
        WHERE
            I.TypeID = 'A'
        ;
    
        SET i = 1;
        REPEAT
            INSERT INTO
                Result
            SELECT
                `Name`,
                CAST(STRSPLIT(ValueList, ' ', i) AS CHAR(128)) AS Value
            FROM
                TempList
            WHERE 
                CAST(STRSPLIT(ValueList, ' ', i) AS CHAR(128)) IS NOT NULL
            ;
    
            SET i = i + 1;
            UNTIL ROW_COUNT() = 0
        END REPEAT;
    
        SELECT * FROM Result ORDER BY `Name`;
    END $$
    
    DELIMITER ;
    
    CALL GetNameValues();
    

    Hope this helps someone one day.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom,
I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel
We have a non-profit web site that got about 5 million hits in May.
I have a non-Activity class (let's call it NonActivity) that needs to post a
I have a non-rails application that I want to use rails active-record migrations with.
If I have a non-template (i.e. normal) class and wish to have a template
I have non-ascii chars in velocity template files. And when processed they are garbled.
I have non-template class with a templatized constructor. This code compiles for me. But
I have a non databound DGV (no datasource, etc; rows added manually). To filter
I have a non transparent, colour bitmap with length 2480 and width 3507. Using

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.