Split column string into multiple columns strings

前端 未结 2 853
不知归路
不知归路 2021-01-26 14:33

I have a entry in the table that is a string which is delimited by semicolons. Is possible to split the string into separate columns? I\'ve been looking online and at stackoverf

相关标签:
2条回答
  • 2021-01-26 14:48

    You could make use of String functions (particularly substr) in mysql: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

    0 讨论(0)
  • 2021-01-26 14:51

    Please take a look at how I've split my coordinates column into 2 lat/lng columns:

    UPDATE shops_locations L 
    LEFT JOIN shops_locations L2 ON L2.id = L.id
    SET L.coord_lat = SUBSTRING(L2.coordinates, 1, LOCATE('|', L2.coordinates) - 1), 
    L.coord_lng = SUBSTRING(L2.coordinates, LOCATE('|', L2.coordinates) + 1)
    

    In overall I followed UPDATE JOIN advice from here MySQL - UPDATE query based on SELECT Query and STR_SPLIT question here Split value from one field to two

    Yes I'm just splitting into 2, and SUBSTRING might not work well for you, but anyway, hope this helps :)

    0 讨论(0)
提交回复
热议问题