1

i have field that has records like '1:23,2:23' and '2:43'

is there any way to split string into 1,23,2,23 (separate values, so i can work with them independently) using mysql query. for example add them to another table like

 row1:   1 | 23
 row2:   2 | 43 

the string can contain more pairs of keys/ values

OMG Ponies
  • 314,254
  • 77
  • 507
  • 490
samrockon
  • 873
  • 3
  • 11
  • 17

3 Answers3

0

Check out regular expression matching

http://dev.mysql.com/doc/refman/5.1/en/regexp.html

kobrien
  • 2,661
  • 2
  • 21
  • 33
0

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

Just replace ':' with ','.

Vjy
  • 2,076
  • 3
  • 20
  • 32
0

I may misunderstand your question but here are my thoughts...

SQL is meant to fetch data, not parse it. Parsing should happen on the application side. If you need to create a list for something like an IN clause then you probably need to reconsider you data-model to allow the values you would normally parse out to be in separate rows.

I am not saying you can't do some string magic in SQL but it's usually a sign of a design issue.

Andrew White
  • 51,542
  • 18
  • 111
  • 135