1

I have a column named "tel". This column has some records that start with (for example) "0511" and I want to change it "0513". What is proper query?

Ali Behzadian Nejad
  • 8,804
  • 8
  • 56
  • 106
  • Have you see that one: http://stackoverflow.com/questions/10532656/sqlite-replace-part-of-a-string? – Trinimon Nov 02 '14 at 10:14

3 Answers3

0

You can use replace function

 UPDATE table SET tel= replace( tel, '0511', '0513' ) WHERE tel LIKE '0511%';

Check the SQLite core functions here

EDIT In case you have a match after the first 4 digits of your tel number. For example 051121505113

  UPDATE table SET tel= replace(substr(tel,1,5), '0511', '0513' )||substr(tel,5) 
  WHERE tel LIKE '0511%';
geoandri
  • 2,360
  • 2
  • 15
  • 28
0
UPDATE table
SET tel = REPLACE(tell, '0511', '0513')
WHERE tel like '%0511%' 
Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48
0

In case there's a risk that '0511' exists within the rest if the string you can make sure to only replace 0511 at the start of the string like this:

UPDATE [table]
 SET [tel] = CASE WHEN 
  instr([tel], '0511') = 1  THEN 
    '0513' || substr([tel], 4)
  ELSE    
    [tel]
  END
WHERE [tel] LIKE '0511%';
becquerel
  • 1,131
  • 7
  • 11