![]() Its syntax isįor the expression argument, you write a string literal or specify a column from which you want to extract the substring. The start argument is an integer indicating the numeric position of the character in the string where the substring begins. The length argument, as the name says, defines the length, an integer value, of the substring to be returned. ![]() ![]() The clue is in the function’s name itself. A substring is a string within the main string. Therefore, SUBSTRING() extracts a substring as you specify in its argument. In the string above, the substring that starts at position 1 and has a length of three characters is ‘STR’. 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. 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. This means: I want to find a substring from the text ‘This is the first substring example’. ![]() Let’s see what this code returns: substring_extraction The arguments say that the substring starts at the 9th character of the string and that its length is 10 characters. This is the most basic use of SUBSTRING() the code doesn’t even use any tables! The Employees Table To show you more interesting examples, I need some data. The table stores information about the employees of an imaginary company Kooler in the following columns: Let me introduce you to a table named employees. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |