1

i have table name master and column name with number

column number have value = A011017

I want change 5=0 change with 2

i have try with this code

update master set number =substr(number,5,1) where number like 'A011%'

I want change all rows with 2 in the 5th position

Help me please

8
  • 1
    "column Number have value = A011017 I want change 5=0 change with 2"...please explain it clearly. Commented Dec 3, 2013 at 11:03
  • maybe A011017 to A011217? Commented Dec 3, 2013 at 11:03
  • i mean record number 5 from A011017 is zero (0) i want change value with 2 Commented Dec 3, 2013 at 11:05
  • for all records whose start vith A011 or only for this one? Commented Dec 3, 2013 at 11:07
  • All record whose start vith A011 Commented Dec 3, 2013 at 11:07

1 Answer 1

2

Something like this?

update master 
set number =
concat(substring(number,1,4),"2",substring(number,6))
where number like 'A0110%'
;

You can adjust the where clause accordingly (not sure whether you want all rows with 0 in the 5th position or just those rows starting with 'A011'). For example, if you want to change all rows with '0' in the 5th position to have '2' in the 5th position then use this:

update master 
set number =
concat(substring(number,1,4),"2",substring(number,6))
where substring(number,5,1) = "0"
;

...or if you want to change all rows with '2' in the 5th position to have '0' in the 5th position then use this:

update master 
set number =
concat(substring(number,1,4),"0",substring(number,6))
where substring(number,5,1) = "2"
;
Sign up to request clarification or add additional context in comments.

2 Comments

I want change all rows with 2 in the 5th position
I want change all rows with 2 in the 5th position

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.