Scott
Scott

Reputation: 3

Remove first number from Column MySql

I have a column that just has 4 numbers and I want to remove the first. I Run a update query I found on here but it says no columns affected.

 UPDATE mytable
 SET mycol = TRIM(LEADING '[0-9]' FROM mycol)

I don't get an error when I run it just does not do anything.

Upvotes: 0

Views: 883

Answers (2)

Rimas
Rimas

Reputation: 6024

You can test mycol has digit with mycol RLIKE '^[0-9]', remove with SUBSTRING(mycol, 2):

UPDATE mytable
 SET mycol = SUBSTRING(mycol, 2)
 WHERE mycol RLIKE '^[0-9]'

Documentation:

Upvotes: 1

takeit
takeit

Reputation: 4081

Try:

UPDATE `tablename`
SET `columnname` = 
TRIM(LEADING  'THE CHARACTER YOU WANT TO REMOVE, eg: 1'  FROM `columnname`);

Upvotes: 1

Related Questions