SQL substr
时间: 2023-08-31 08:07:22 浏览: 43
SUBSTR is a SQL function that is used to extract a substring from a string. It takes three parameters: the input string, the starting position, and the length of the substring.
The syntax for using SUBSTR in SQL is as follows:
```sql
SUBSTR(input_string, starting_position, length)
```
Here's an example to demonstrate how it works:
```sql
SELECT SUBSTR('Hello World', 7, 5) AS result;
```
In this example, the starting position is 7 and the length is 5. So, the substring 'World' will be extracted from the input string 'Hello World'. The result of this query will be 'World'.
You can also use negative values for the starting position parameter to count positions from the end of the string. For example:
```sql
SELECT SUBSTR('Hello World', -5, 5) AS result;
```
In this case, the substring 'World' will still be extracted because the negative starting position of -5 counts from the end of the string.
I hope this helps! Let me know if you have any more questions.