D
D
di2021-07-18 10:07:20
MySQL
di, 2021-07-18 10:07:20

How to replace rows in a column with new ones with a certain length?

there is an items table, there is an item_code column. is a string (varchar), is a certain sequence of numbers.
it is necessary to replace item_code with a short one (last 6 characters) if there are more than 6 characters , that is, 1234567 -> 234567 123456789-> 456789
I can’t understand if this is possible and if so, how? regular expressions to use?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N, 2021-07-18
@Delgus

UPDATE `table` SET `field_code` = SUBSTR(`field_code`, -6, 6) WHERE LENGTH(`field_code`) > 6;

Be sure to make a backup before this request , because. in case of an error, the old data cannot be returned ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question