Search for text between delimiters in MySQL

前端 未结 11 2407
情歌与酒
情歌与酒 2021-02-08 03:39

I am trying to extract a certain part of a column that is between delimiters.

e.g. find foo in the following

test \'esf :foo: bar

So in the above I\'d wa

11条回答
  •  野性不改
    2021-02-08 04:11

    If you know the position you want to extract from as opposed to what the data itself is:

    $colNumber = 2; //2nd position
    $sql = "REPLACE(SUBSTRING(SUBSTRING_INDEX(fooField, ':', $colNumber),
                                 LENGTH(SUBSTRING_INDEX(fooField, 
                                                        ':', 
                                                        $colNumber - 1)) + 1)";
    

提交回复
热议问题