Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the first characters in a column

Tags:

mysql

I have a column that contains string. It is a number but saved as string. The string might start with 00 or more than two zeros. I need to remove the zeros and insert the new value (after removing) into another column. The problem is the number of zeros at the beginning is not fixed. It can be 2 or more. Is this task possible to be done with MySQL ? How?

like image 219
Jury A Avatar asked Sep 01 '12 19:09

Jury A


People also ask

How do I remove the first character from a column in Excel?

Remove first character in Excel To delete the first character from a string, you can use either the REPLACE function or a combination of RIGHT and LEN functions. Here, we simply take 1 character from the first position and replace it with an empty string ("").

How do I remove the first 3 characters in Excel?

=RIGHT(B4,LEN(B4)-3) Here, string_cell is B4 from where we will remove 3 characters. LEN(B4)-3 is used as the num_chars. The LEN function will make sure to remove the first 3 characters from the cell.

How do I remove the first 4 characters in Excel?

The formula =RIGHT(A2,LEN(A2)-4) in cell B2 is used to remove the first four characters in the product code.

How do I remove the first 5 characters in Excel?

Right() function You can delete the first 5 characters in Excel using the Right and LEN functions. This is how the formula works. Formula: =RIGHT(string_cell,LEN(string_cell)-n_character).


1 Answers

A good hint is provided here:

UPDATE your_table
SET column2 = TRIM(LEADING '0' FROM column1)

supposing that the original value is stored in column1 and you want to write the 0-trimmed one in column2

like image 104
Dalen Avatar answered Oct 15 '22 19:10

Dalen