JElster
asked on
mySQL - help parsing column data
Hi..
I have a comments field with Error codes and messages. The data looks like this.
"Error 1.0 Big Error Error 2.0 Disk Error Error 3.0 I/O Error"
I need to parse the 3 error codes out (Some may have 2 or more)
I need to use Error X.X as the 'delimiter' So I get 3 separate records
Error 1.0 Big Error
Error 2.0 Disk Error
Error 3.0 I/O Error
Any ideas?
thx
I have a comments field with Error codes and messages. The data looks like this.
"Error 1.0 Big Error Error 2.0 Disk Error Error 3.0 I/O Error"
I need to parse the 3 error codes out (Some may have 2 or more)
I need to use Error X.X as the 'delimiter' So I get 3 separate records
Error 1.0 Big Error
Error 2.0 Disk Error
Error 3.0 I/O Error
Any ideas?
thx
ASKER
No.. I could be any number after the word 'Error'
Will it always be a number? Will there be any other numbers present?
How about the three spaces?
Will there be any other dots in the entire field besides the ones in the numbers?
How about the three spaces?
Will there be any other dots in the entire field besides the ones in the numbers?
ASKER
Yes, no just single number like 1.0 99 123
at least 1 space after Error
Could be dots or periods in sentences.
thx
at least 1 space after Error
Could be dots or periods in sentences.
thx
Will ever segment look like this?
"Error nnnn Something Error"
Are there always THREE spaces between segments?
Do you have any control over how this string is originally formatted?
I'm trying to find a way to distinguish the "Error nnn" part from the "Something Error" part.
"Error nnnn Something Error"
Are there always THREE spaces between segments?
Do you have any control over how this string is originally formatted?
I'm trying to find a way to distinguish the "Error nnn" part from the "Something Error" part.
ASKER
Yes.. It would look like that
Error 1 Something Error Error 2 Something Error Error 25.6 Something Error
The 'delimiter' will be 'Error N'
thx
Error 1 Something Error Error 2 Something Error Error 25.6 Something Error
The 'delimiter' will be 'Error N'
thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx.. but I don't know or have PHP.
Can it be done in SQL?
Can it be done in SQL?
yikes, I doubt it, there are too many insecure formatting problems, such as variable number of spaces, double use of the word "Error", etc. Using explode() was the only way I could think of to do it, and MySQL doesn't have an equivalent function.
Is this format something you have control over? Wherever this comments field is created, do you have the ability to change the format/contents?
Is this format something you have control over? Wherever this comments field is created, do you have the ability to change the format/contents?
I'm sorry but I will have to be gone most of the day today. I'll check back tonight when I get home.
In the meantime, see if you can follow what I did in php:
1. Strip out all extra spaces
2. Divide the string up based on the word "Error"
3. Take pairs of the remaining as Number/Description pairs
4. Reassemble as needed
and see if you can find some MySQL functions that will do something similar.
If you have control over the format, perhaps we can simplify the entire problem by changing the formatting.
In the meantime, see if you can follow what I did in php:
1. Strip out all extra spaces
2. Divide the string up based on the word "Error"
3. Take pairs of the remaining as Number/Description pairs
4. Reassemble as needed
and see if you can find some MySQL functions that will do something similar.
If you have control over the format, perhaps we can simplify the entire problem by changing the formatting.
We are looking at one row with three different data elements in the same column. This is a mistaken design. The correct way to organize this data is to have three rows, each with one of the data elements. If you find that you have to "parse" any column of a data base, it's a definite code smell that suggests a need to reorganize the data. I think the best way forward is to reorganize now, before it becomes more difficult and expensive. Instead of inserting multiple data elements into the same column, make two separate INSERT statements to put the data elements into separate rows.
Are the n numbers always in order?
SInce you cannot cue on the word "Error", can you reliably cue on the dot to identify the separate fields? How about THREE spaces that seem to separate the sections, can you reliably cue on that?