PDA

View Full Version : MySQL help - isolating a substring


MacMorag
08-03-2004, 05:07 PM
Working directly on the database via phpmyadmin, how do I extract "XXXX" from the following string. I will store "XXXX" in a new field:

String:

abcabcabcabcXXXXabcabcabcabc


the "abc..." bits are variable, but there is always one instance of and .

I'm guessing that I need something that creates a substring after "" and before "" - but MySQL knowledge is not too great yet :ermm:

I've had a look at www.mysql.com but can't find the answer.

Thanks for any help.

Morag.

Andreas
08-03-2004, 05:26 PM
Try this:
SELECT SUBSTRING('abcabcabcabcXXXXabcabcabcabc', LOCATE('', 'abcabcabcabcXXXXabcabcabcabc') + 5, LOCATE('', 'abcabcabcabcXXXXabcabcabcabc') - LOCATE('[pic]', 'abcabcabcabcXXXXabcabcabcabc') -5) AS pic

Admin Note: SQL-Tag is buggy!