SQLite is a database engine. It is a serverless architecture as it does not require any server to process queries. Since it is serverless, it is lightweight and preferable for small datasets. It is used to develop embedded software. It is cross-platform and available for various Operating systems such as Linux, macOS, Windows, Android, and so on.
Replace Statement
REPLACE Statement is a type of Statement that helps us to replace one part of a string with another string. It is an INSERT OR REPLACE command which means if the record already exists in the table then it replaces the substring with a new string, but if the record does not exist in the table then INSERT new record into the table. The REPLACE Statement is similar to the INSERT statement. We will understand everything with the help of examples.
Syntax:
SELECT REPLACE(A,B,C)
- A -> Original String present in the Table.
- B -> Substring or string that we need to replace.
- C -> Replace string.
Examples 1:
Let's say we have an 'ABC DEF ANM ADK DLM' string and we have to replace substring 'A' with 'S' String. here we use REPLACE Statement.
SELECT REPLACE('ABC DEF ANM ADK DLM', 'A', 'S')
Output:
SBC DEF SNM SDK DLM
Explanation: In the output you can clearly see that all substring where earlier 'A' lies but after REPLACE statement it change with 'S' string.
Example 2:
If the second string does not exist then it replace nothing and returns the original string.
SELECT REPLACE('ABC DEF ANM ADK DLM', ' LA', 'S')
Output:
ABC DEF ANM ADK DLM
Explanation: In the above query we are trying to replace all substring 'LA' with 'S'. Their is no subtsring with 'LA', hence, it returns the original string.
Example 3:
What if we are trying to find substring which is empty string and we want to replace it with another string. Does REPLACE work with empty string ? Let's understand .
SELECT REPLACE('ABC DEF ANM ADK DLM', ' ', 'S')
Output:
ABC DEF ANM ADK DLM
Explanation: In the above query we are trying to replace string with the empty substring. But REPLACE statement is not work with empty string so it return Original string and nothing will change.
Example with Table
Let's say we have a Employee table and a coulumn named employee name. Now we want to replace 'BC' with '##' evrytime when BC appears in empname coloumn. To do this we can use the REPLACE statement.
Employee TableSELECT empid,empname,city,REPLACE(empname, 'BC', '##') newName FROM Employee
Output:
After REPLACE OperationExplanation: In the above query, we have replaced all empname whose name contains 'BC' as substring with '##'. After performing the REPLACE statement our new employee table will look the above table.
Similar Reads
SQL CASE Statement
The CASE statement in SQL is a versatile conditional expression that enables us to incorporate conditional logic directly within our queries. It allows you to return specific results based on certain conditions, enabling dynamic query outputs. Whether you need to create new columns, modify existing
4 min read
PL/SQL UPDATE Statement
The UPDATE statement in the PL/SQL(Procedural Language/ Structural Query Language) is the powerful SQL (Structured Query Language) command used to modify the existing data in the database table. In this article, we will explain the PL/SQL UPDATE Statement, its syntax, and examples in detail. PL/SQL
7 min read
SQLite Update Statement
SQLite is a database engine. It is a software that allows users to interact with relational databases, Basically, it is a serverless database which means it does not require any server to process queries. With the help of SQLite, we can develop embedded software without any configurations. SQLite is
3 min read
SQL Server SELECT INTO Statement
SQL Server is a relational database management system. SQL Server offers robust security features to protect data integrity and confidentiality. It includes authentication, authorization, encryption, and various mechanisms to secure the database environment. It is designed to scale from small applic
6 min read
SQL INSERT INTO SELECT Statement
In SQL, the INSERT INTO statement is used to add or insert records into the specified table. We use this statement to insert data directly into a table by specifying column names in a specific order. The SELECT statement is used to retrieve data from the table, and it can be used in conjunction with
6 min read
MySQL - ALTER VIEW Statement
The ALTER VIEW statement in MySQL is a powerful tool that allows users to modify the definition of an existing view without the need to drop and recreate it. This statement is particularly useful for changing the query or structure of a view to better help the needs of the application or database de
5 min read
SQLite Alter Table
SQLite is a serverless architecture that we use to develop embedded software for devices like televisions, cameras, and so on. It is written in C programming Language. It allows the programs to run without any configuration. In this article, we will learn everything about the ALTER TABLE command pre
4 min read
SQL INSERT INTO Statement
The SQL INSERT INTO statement is one of the most commonly used commands for adding new data into a table in a database. Whether you're working with customer data, products, or user details, mastering this command is crucial for efficient database management. Letâs break down how this command works,
6 min read
SQL RENAME TABLE
Renaming a table is a common and useful operation for database administrators and developers. It is especially useful when we need to correct a naming mistake, organize our database schema, or update the table name to reflect new business requirements. In this article, we will provide a detailed gui
6 min read
SQLite WHERE Clause
SQLite is the serverless database engine that is used most widely. It is written in c programming language and it belongs to the embedded database family. In this article, you will be learning about the where clause and functionality of the where clause in SQLite. Where ClauseSQLite WHERE Clause is
3 min read