India's No. #1 Programmer's Forum


How to update and Replace one field First Character Using Mysql

Asked by Sonu Yadav On 21 Mar, 2021 10:07:08pm

63

2


I have a table named student, but now I want to replace values in column roll_no
The values are like this:
0850154
0254403
0254144
1236541
8470111
What I want to achieve:
850154
254403
254144
1236541
8470111

Just changing the '0' to ''(Blanck) as first character

Re: How to update and Replace one field First Character Using Mysql

21 Mar, 2021 10:26:57pm
Answer by Chandraket

0

This above answer is correct and use below code

UPDATE student  SET roll_no=CONCAT('', SUBSTRING(roll_no  FROM 2)) where left(roll_no,1)='0';


Re: How to update and Replace one field First Character Using Mysql

21 Mar, 2021 10:12:16pm
Answer by Expert

3

Use the below query:
UPDATE student SET roll_no=CONCAT('', SUBSTRING(roll_no FROM 2)) where substring(roll_no,1,1)='0'

OR

UPDATE student  SET roll_no=CONCAT('', SUBSTRING(roll_no  FROM 2)) where left(roll_no,1)='0';

It will be work fine :)-


Related Question

CodexEra
Sales Team
sales@codexera.com

Note: If you have a project that you want to get started, launch quickly, contact Us. @9990437464
Talk to us
WhatsApp