How to substring a MySQL table column

后端 未结 6 2122
借酒劲吻你
借酒劲吻你 2020-12-25 09:32

I want to select a field from table and substring it.

For example:

VAN1031 --> 1031

I tried this, but is improper syntax:

<
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-25 10:36

    You don't need the third argument (length) if you want to select all the characters to the right of a specific index:

    SELECT SUBSTR(R.regnumber, 4)
    FROM registration AS R
    

    I also changed the start index to 4 because in SQL strings are 1-indexed and not 0-indexed as they are in many popular programming languages.

提交回复
热议问题