MYSQL remove the first comma from a string

时间:2018-07-25 04:26:23

标签: mysql

I have a string variable SET @my_str=,2,4,7,1 and I want to remove the first char (comma). What I tried is SET @my_str=substr(@my_str,1) but it does not work.

Am I doing something wrong?

1 个答案:

答案 0 :(得分:1)

The index is 1-based, so you will need to start at 2:

SET @my_str=substr(@my_str,2)

See https://www.w3schools.com/sql/func_mysql_substr.asp