views:

162

answers:

1

I have a field that has values like this...

s:10:"03/16/1983"; s:4:"Male"; s:2:"No";

I'd like to parse out the quoted values.

its going to be some sort of combination of substr and instr

its the doublequote i have issues finding its position.

i have tried things like select substr(field_value, instr(field_value,'"'),instr(field_value,'"',null,2)) from table where etc

apologies a noob question...

+1  A: 

Here's something that should work (unable to test at the moment):

select substr(substr(field_value, instr(field_value,':')+1, CHAR_LENGTH(field_value)-1),
              instr(substr(field_value, instr(field_value,':')+1, CHAR_LENGTH(field_value)-1),':')+1)

Edit: Putting my comment in the answer:

select substr(field_value, instr(field_value,'\"'),CHAR_LENGTH(field_value)-1)
Lance Roberts
this is perfect but i need what is in the double quotes not colons. that was more what i was having problems figuring out. is it '"'? or do i escape it like "\"" in sql i have no idea. thank you though! that helps me get closer!
Kirby
What I was trying to do was use the fact that all your examples had the string after the second colon, then exploit that to grab the string, without ever messing around with the double quotes. I don't like useing strategies that have to use specific knowledge like this, since it could change, but I've had to do it before.
Lance Roberts
ok then what about a regex find and replace to remove "s ... or is that silly?
Kirby
mysql is also telling me the len function does not exist.
Kirby
i found it... in mysql it is CHAR_LENGTH instead of len
Kirby
sorry, for MySQL it's Length(), I'll edit my answer. Someone will probably come along and tell you how to escape out the double quotes, I just don't know off the top of my head.
Lance Roberts
you're right, CHAR_LENGTH would be better to use.
Lance Roberts