The Little Guy Posted July 6, 2011 Share Posted July 6, 2011 I want to extract a number from a string and place it into a new column. The string looks like this: Bonus AdPacs from Product purchase #1234567890 I was thinking that REGEXP would work, but that returns 1 or 0, not the number. Using mysql how can I get that number? I don't want to use PHP for this. Any ideas would be helpful! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/241241-extract-number-into-new-column/ Share on other sites More sharing options...
xyph Posted July 6, 2011 Share Posted July 6, 2011 Ooops, redoing. One sec. SET @str='Bonus AdPacs from Product purchase #1234567890'; SELECT SUBSTRING( @str, LOCATE('#', @str)+1 ) Quote Link to comment https://forums.phpfreaks.com/topic/241241-extract-number-into-new-column/#findComment-1239177 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2011 Share Posted July 6, 2011 Do all the numbers start with the # and will there only be one # in each string? Quote Link to comment https://forums.phpfreaks.com/topic/241241-extract-number-into-new-column/#findComment-1239178 Share on other sites More sharing options...
The Little Guy Posted July 6, 2011 Author Share Posted July 6, 2011 Do all the numbers start with the # and will there only be one # in each string? yes and yes. I decided to do substring(), which worked in this case. Quote Link to comment https://forums.phpfreaks.com/topic/241241-extract-number-into-new-column/#findComment-1239192 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.