substring返回分隔符后的所有值

时间:2010-08-31 06:49:21

标签: mysql

如何在第一个分隔符后获取所有值?在下面的例子中,我期待'xyz @ yahoo.com,pqr @ company.com'

(02:40) mysql>select substring_index('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',',  1) as first;
+-----------------+
| first           |
+-----------------+
| abc@hotmail.com |
+-----------------+
1 row in set (0.00 sec)

(02:41) mysql>select substring_index('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',',  -1) as last;
+-----------------+
| last            |
+-----------------+
| pqr@company.com |
+-----------------+
1 row in set (0.00 sec)

1 个答案:

答案 0 :(得分:5)

   select substring('abc@hotmail.com,xyz@yahoo.com,pqr@company.com',
   instr('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',') + 1) as first;