Home  >  Article  >  Database  >  How to intercept the first digits of a string in sql

How to intercept the first digits of a string in sql

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-05-08 17:07:2539017browse

In SQL, you can use the SUBSTRING function to intercept a string. The syntax format is "SUBSTRING (string, 1, interception length)". The SUBSTRING function is used to grab part of a string, binary string, text, image, column, or expression containing a column.

How to intercept the first digits of a string in sql

The operating environment of this tutorial: windows7 system, mysql8.0 version, Dell G3 computer.

SUBSTRING ( expression, start, length )

Parameters

expression

String, binary string, text, image, column, or expression containing columns. Do not use expressions containing aggregate functions.

start

Integer or expression that can be implicitly converted to int, specifies the starting position of the substring, and the index starts from 1.

#length

An integer or an expression that can be implicitly converted to int, specifying the length of the substring. After testing, it was temporarily found that it can only be a non-negative number.

Return value

1. If expression is a supported binary data type, binary data is returned. We will not discuss this case for now.

2. If expression is a supported character data type, character data is returned.

(1) If the index of start|starts from 1, then the string interception starts from the first character of the expression, and from 2, it starts from the second character of the expression. And so on.

For example:

SELECT SUBSTRING('成都融资事业部',1,2)//结果:成都

Related recommendations: "mysql tutorial"

The above is the detailed content of How to intercept the first digits of a string in sql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn