0

Possible Duplicate:
Can Mysql Split a column?

I am going to pass a comma separated string consisting of filter parameters from my java code to my mysql stored procedure. This will be fetched by one of the IN parameters of the procedure.

I want to split this comma separated string into separate variables and use them in different queries.

On googling I found this MySQL substring function

But there is a problem with it:

mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
    -> 'www.mysql'

But I want www,mysql,com for which there is no provision to get the sub-string from 1st delimeter to the next one and so on...

Community
  • 1
  • 1
DarkKnightFan
  • 1,913
  • 14
  • 42
  • 61

1 Answers1

2

MySQL, as well other RDBMS, do not provide this kind of functionalities.

What you are looking for is for this, a fully functional splitter function.

What you want has been asked several times right here on SO.

Here, here and here you have same question.

Community
  • 1
  • 1
Yaroslav
  • 6,476
  • 10
  • 48
  • 89
  • As Yaroslav stated, this is possible, however you will run into problems when separating variables that may contain a comma. – Kermit Sep 20 '12 at 13:40
  • @njk I don't think so, if you take a look into the function, it has a 2 parameters, the second one is the delimiter you want to use, it can be anything, comma, dot, slash. I've not tested to see if can be some weird character too or even more than 1 character. – Yaroslav Sep 20 '12 at 13:43
  • Yes, there is. Take a look at [this](http://stackoverflow.com/questions/2182668/how-to-split-comma-separated-text-in-mysql-stored-procedure) and [this](http://stackoverflow.com/questions/9953114/split-comma-delimited-string-function-db-charindex-does-not-exist). – Kermit Sep 20 '12 at 13:50