SQLite - replace part of a string
You can use the built in replace()
function to perform a string replace in a query.
Other string manipulation functions (and more) are detailed in the SQLite core functions list
The following should point you in the right direction.
UPDATE table SET field = replace( field, 'C:\afolder\', 'C:\anewfolder\' ) WHERE field LIKE 'C:\afolder\%';
SQLite: replace part of a string with another one
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%';
Android SQLite - replace part of a string safely
Use bind variables. Simply place a ? where you have a variable, and pass an array of parmaeters, in order, to the rawQuery function.
You should NEVER use concatenation like you did above. Use bind variables everywhere. Anything user input should be in the bind variable, anything constant should be in the query. That eliminates all possible SQL injection.
How to replace part of column String SQLite3 with Python
The problem here is you are printing the first column which is English
whereas the replacement is actually happening in the second column of your resultset.
if you update the following line to look for index 1 instead of 0, you'll get the correct results.
...
for row in records:
print(row[1]) # print the second column defined by your replace function.
print("\n")
...
However, it is still not going to update the actual data in the database because SELECT
only queries the data and REPLACE
is performed on the queried copy of the data. To update the data in your database, you need to perform the UPDATE
operation on the database column.
UPDATE
Data
SET
English = REPLACE(English,'"','"');
What is the SQLite query to replace a string of characters with another string that includes a line break?
Use the concatenation operator ||
with the function CHAR()
and don't wrap the function inside the single quotes:
UPDATE [Slovník]
SET Note = replace(Note, '); "', ')' || CHAR(13) || '"')
WHERE Phrase = 1
It's better to use this WHERE
clause:
WHERE Phrase = 1 AND Note LIKE '%); "%'
to avoid unnecessary updates for the rows that do not contain '); "'
.
sqlite replace() function to perform a string replace
Just add a comma to all occurrences of 0.
:
replace(TheColumn, '0.', ',0.')
then remove the duplicates:
replace(replace(TheColumn, '0.', ',0.'), ',,', ',')
and the comma at the beginning:
substr(replace(replace(TheColumn, '0.', ',0.'), ',,', ','), 2)
Related Topics
Select Values That Begin with a Number
Delete All Records Except the Most Recent One
How to Add 10 Seconds in Current_Timestamp SQL ( Oracle )
Why Would You Use "As" When Aliasing a SQL Table
Group by Two Columns and Display Grand Total in Every Row
Execution Order of Conditions in SQL 'Where' Clause
Database Normalization - Who's Right
Querying More Than 65536 Rows Error in Excel 2013
SQL Server 2005 Recursive Query with Loops in Data - Is It Possible
Stored Procedure Parameter Default Value - Is This a Constant or a Variable
If I Stop a Long Running Query, Does It Rollback
Why SQL Server Go Slow When Using Variables
Sql: Group by on Consecutive Records
SQL Coalesce with Empty String
Calculate Time Difference (Only Working Hours) in Minutes Between Two Dates