This means: I want to find a substring from the text ‘This is the first substring example’. SELECT SUBSTRING('This is the first substring example', 9, 10) AS substring_extraction You can write the string explicitly as an argument, like this: The SUBSTRING() function returns a substring from any string you want. Starting, of course, with the simplest one! Example 1: Substring From a String Literal Now that we have the principles covered, let me show you several examples. In the string above, the substring that starts at position 1 and has a length of three characters is ‘STR’. Therefore, SUBSTRING() extracts a substring as you specify in its argument. A substring is a string within the main string. The clue is in the function’s name itself. The length argument, as the name says, defines the length, an integer value, of the substring to be returned. The start argument is an integer indicating the numeric position of the character in the string where the substring begins. Its syntax isįor the expression argument, you write a string literal or specify a column from which you want to extract the substring. SUBSTRING() is a text function that allows you to extract characters from a string. Some examples may feel complicated if you’re not familiar with the text functions, so make sure you have the Standard SQL Functions cheat sheet or an overview of SQL text functions by your side. In this article, we have five real-life business examples that cover the main uses of this function. One of the common text functions the course covers is SUBSTRING(). It contains 211 exercises and teaches you how to use common text, numeric, and date-and-time functions in SQL. The functions that let you do so are called text functions.įor anyone who wants to practice SQL functions, I recommend our interactive Standard SQL Functions course. Not only do you have to extract it, but often you also have to manipulate it. But text is data, too! It’s very common to find text data in databases. When you think of working with data in SQL, your first thought is probably a database full of numbers and your SQL code doing very fancy calculations. Working with text data in SQL? We explain how to get values from any point in a string.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |