Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove characters from a string in sqlite3 database?

i have a string like this a) Text in my sqlite databse..i want to remove a) from databse..anyone know a query for this?

like image 695
Rahul Vyas Avatar asked Aug 12 '09 14:08

Rahul Vyas


People also ask

What is Substr in SQLite?

The substr() function extracts and returns a substring from string . The position of the substring is determined by index and its length is determined by count . If any parameter is NULL, a NULL will be returned. Otherwise, if string is not a BLOB it will be assumed to be a text value.

What are the three arguments for the substr () function in SQLite?

SQLite substr() returns the specified number of characters from a particular position of a given string. A string from which a substring is to be returned. An integer indicating a string position within the string X. An integer indicating a number of characters to be returned.

How do I remove something from a table in SQLite?

The TRUNCATE TABLE statement is used to remove all records from a table. SQLite does not have an explicit TRUNCATE TABLE command like other databases. Instead, it has added a TRUNCATE optimizer to the DELETE statement. To truncate a table in SQLite, you just need to execute a DELETE statement without a WHERE clause.

How do I delete a specific character in SQL?

SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string. Note: Also look at the LTRIM() and RTRIM() functions.


1 Answers

@laalto's answer is close, but it will not work on edge cases, specifically if 'a) ' occurs elsewhere in the string. You want to use SUBSTR to only remove the first 3 characters.

sqlite> SELECT REPLACE ("a) I have some information (or data) in the file.", "a) ", "");
I have some information (or datin the file.

sqlite> SELECT SUBSTR ("a) I have some information (or data) in the file.", 4);
I have some information (or data) in the file.

So updating his query, it should turn into:

UPDATE tbl SET col=SUBSTR(col, 4) WHERE col LIKE 'a) %';

... noting that strings are indexed from 1 in SQLite.

like image 92
Mark Rushakoff Avatar answered Oct 23 '22 20:10

Mark Rushakoff