I have a MySQL table with just a single text type column with lots of information in the same format, starting with a string like this:
Field1 : 1234
Field2 : Something
The column always starts with Field1 and Field2, but the values after each Field are different for each record.
What I need is to get the just the values of what’s after Field1 and Field2 (in this case 1234 and Something) on a Query, the value after Field1 is easy because it’s always 4 characters long, but the problem is the one after Field2 because it’s size varies for each record, what I have so far is this:
SELECT SELECT substring(substring_index(COLUMN,'Field1 : ',-1),1,4) as Field1_value
FROM table
I know after Field2‘s value there’s a line break, so I’ll think of considering the \n character to delimit the value I need.
How do I get this substring of variable size for each row?
P.S. Yes the data is horribly structured, I’m not able to change it…
Well, finally I got it (thanks for your contributions everybody), this is the final resulting Query:
Knowing the size of the strings “Field1 : ” and “Field2 : “, this isolates those 2 strings and their following values from the rest of column’s text, and then I use a substring (knowing that the value after Field1 is always 4 characters long helps), and the 15 in the substring is to ensure I look not for the second line break.