0

I am new to MySQL and i am storing a version number in a column called version which is a string.I want to convert it into integer and increment by one. For example if version = 2.2.1....By running a query i want to change it to 2.2.2 is there anyone who did similar queries?

1

1 Answer 1

1

You could use some string function

SELECT CONCAT(
    LEFT(your_column, LENGTH(your_column) - LOCATE('.', REVERSE(your_column))+1), 
        CAST(SUBSTRING_INDEX(your_column, '.', -1) AS UNSIGNED) +1
)

eg

SELECT CONCAT(
    LEFT("2.2.2", LENGTH("2.2.2") - LOCATE('.', REVERSE("2.2.2"))+1),  
        CAST(SUBSTRING_INDEX("2.2.2", '.', -1) AS UNSIGNED) +1
)
Sign up to request clarification or add additional context in comments.

1 Comment

this query is giving result as 2.2..1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.