SQL substring extract some strings

Source: Internet
Author: User

Function:Returns part of a character, binary, text, or image expression.

Syntax:Substring (expression, start, length)

The substring function in SQL is used to capture part of a column. The function names are not exactly the same in different databases:

Parameters:

Expression string, binary string, text, image, column, or expression that contains a column. Do not use expressions that contain aggregate functions.

The START integer or expression that can be implicitly converted to int, which indicates the start position of the stator string.

An integer or expression that can be implicitly converted to an int. It refers to the length of the substring.

Return Value:

If expression is a supported character data type, character data is returned. If expression is a supported binary data type, binary data is returned. If start = 1, the substring starts with the first character of the expression.

The type of the returned string is the same as that of the given expression (except for the content shown in the following table ).

Given expression Return type

Image

Varbinary

Ntext

Nvarchar

CodeExample:

The following example returns the first and last names of each employee in the Employees table:

Select substring (first name, 1, 1) as initial, last name
From employees

The following is the result set:

Initial ...... last name
-------------------------
A ...... funk
M... Pearson
L ...... calafato
N ...... Danner
J... Lee
S... byham
M... Sutter
R... King
A...
    • MySQL: substr (), substring ()
    • ORACLE: substr ()
    • SQL Server: substring ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.