我有一个看起来像这样的字符串:
pi_18944000_780345308_54210001000_345900_text
如何提取其中的所有 ID 并存储它?
我试过这样的事情:
set @a = (SELECT
SUBSTRING(SUBSTRING(SUBSTRING('pi_18944000_780345308_54210001000_345900_text',
(LOCATE('_', 'pi_18944000_780345308_54210001000_345900_text'))), 2), 1,
LOCATE('_', SUBSTRING(SUBSTRING('pi_18944000_780345308_54210001000_345900_text',
(LOCATE('_', 'pi_18944000_780345308_54210001000_345900_text'))), 2)) - 1)
);
select @a;
set @b = (SELECT
SUBSTRING(SUBSTRING(SUBSTRING(SUBSTRING(SUBSTRING(
'pi_18944000_780345308_54210001000_345900_text' , ( LOCATE('_', 'pi_18944000_780345308_54210001000_345900_text' )) ), 2),
LOCATE('_', SUBSTRING(SUBSTRING( 'pi_18944000_780345308_54210001000_345900_text', ( LOCATE('_', 'pi_18944000_780345308_54210001000_345900_text'
))), 2))), 2), 1, LOCATE('_', SUBSTRING(SUBSTRING(SUBSTRING(SUBSTRING( 'pi_18944000_780345308_54210001000_345900_text' , (
LOCATE( '_', 'pi_18944000_780345308_54210001000_345900_text' ))), 2),
LOCATE('_', SUBSTRING(SUBSTRING( 'pi_18944000_780345308_54210001000_345900_text', (
LOCATE('_', 'pi_18944000_780345308_54210001000_345900_text' ))) , 2))), 2)) - 1) );
select @b;
这行得通,但它真的很复杂。只是想看看是否有更好的方法来做到这一点?