Split comma delimited string --> FUNCTION db.CHARINDEX does not exist

前端 未结 2 377
情书的邮戳
情书的邮戳 2020-11-29 06:10

I need to split comma delimited string into a second columns I have the following table :

CL1     POS                 POS2     LENGHT     ALLELE
1       301         


        
相关标签:
2条回答
  • 2020-11-29 06:28

    MySQL doesn't have a built-in CHARINDEX() function. LOCATE() would be the MySQL equivalent.

    Using SUBSTRING_INDEX() might be a more succinct way of doing this. Something like this (disclaimer: untested):

    SUBSTRING_INDEX(POS, ',', 1) for POS

    SUBSTRING_INDEX(POS, ',', -1) for POS2


    As an aside, I may be misunderstanding what you're trying to accomplish, but it looks like you might want to UPDATE existing rows, not INSERT new ones? Something like:

    UPDATE MyTable SET POS2 = SUBSTRING_INDEX(POS, ',', -1);
    UPDATE MyTable SET POS = SUBSTRING_INDEX(POS, ',', 1);
    
    0 讨论(0)
  • 2020-11-29 06:43

    MySQL does have a similar function: InStr or for the same syntax Locate.

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