How to use SUBSTR Function In SQL

The SUBSTR function is used to extract a substring from the given string.

Syntax:

SUBSTR( String , Starting Position , Desired Length)

In this example, we are going to explore SUBSTR function. We are going to cover is basic syntax with well structured example.

Query:

UPDATE w3wiki
SET courses = SUBSTR(courses, 1, 4)
WHERE courses LIKE 'DSA%' ;

Output:

Output

Explanation : In this example, we have used SUBSTR function to extract a part of the string. We have specified changes in courses column where string starts with DSA. We have extract DSA from the string and set it to the column’s value.

How to UPDATE and REPLACE Part of a String in SQLite

In SQLite, updating and replacing parts of a string can be a common task, especially when dealing with textual data. SQLite, serverless architecture offers various methods to solve this problem. In this article, We will learn about string replace in a query with the help of various methods to know how to update and replace a part of the string in SQLite and so on.

Similar Reads

How to UPDATE and REPLACE Part of a String?

When working with SQLite, there are several approaches to update and replace parts of a string. We can achieve this using SQLite’s built-in string functions or through queries that utilize the REPLACE and UPDATE statements. Below are the methods that help to update and replace strings are as follows...

1. Using the REPLACE Function

The REPLACE function is used to replace or modify any specific values. REPLACE function is not a stand-alone statement. We generally use the REPLACE function with UPDATE or SELECT statement....

2. Using SUBSTR Function

The SUBSTR function is used to extract a substring from the given string....

3. Using INSTR Function

The INSTR function is used to find the first occurrence of a specified substring string within a given string....

Conclusion

Overall, updating and replacing parts of a string can be efficiently achieved using the REPLACE function for updating specific parts of a string, the SUBSTR function for extracting substrings, and the INSTR function for finding substring positions. These functions, combined with SQL queries, offer powerful tools for managing and manipulating string data in SQLite databases....