Home > Database > Mysql Tutorial > body text

How to intercept the first digits of a string in sql

醉折花枝作酒筹
Release: 2023-01-05 16:13:55
Original
39041 people have browsed it

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 )
Copy after login

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)//结果:成都
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template