Search code examples
javasqlsqlitein-memory-database

Update (or replace) each cell data of a column in SQLite database table by applying certain conditions


I have created an in-memory sqlite database in a simple Java console application.

What I need to do is go to a certain column and check each and every cell of it, if it has @ at the beginning of the Text data in a cell, then replace it with \@.

I need to understand a generalized replace statement and the conditional replace as mentioned in the example above. Any examples and suggestions would really help.


Solution

  • After wondering for a while, I learned that this can be achieved with a very simple SQL statement

    UPDATE TableName
    SET ColName = REPLACE(ColName , '@', '\@')
    WHERE ColName LIKE '@%';