Introduction to SQL function substr use _mssql

Source: Internet
Author: User

The substr (string, 1, 3) function reads: A string that takes a 3 word length from the left to the right.

The result: Str

From right to left?

There should be another function to provide such a function!

In fact, from right to left this function is just a different parameter.

SUBSTR (string,-1,3) Functional Interpretation: Take the 1 bits to the right of the String to start with 3 bits.

The result is: g

SUBSTR (String,start,length)

String-The specified strings to intercept.
Start-required to specify where to start the string. Positive number-starting at the specified position of the string, minus-starting at the specified position at the end of the string, 0-starting at the first character in the string.
Length-Optionally, specifies the length of the string to intercept, and returns all characters before the end of the value of the character expression by default.

For example: Select substr (' ABCDEFG ', 3,4) from dual; The result is cdef.
Select substr (' ABCDEFG ', -3,4) from dual; Results EFG

Note: The first position in the string is always 1. The results of the following two SQL queries are the same:

For example: Select substr (' ABCDEFG ', 0,3) from dual; The result is ABC.

Select substr (' ABCDEFG ', 1,3) from dual; The result is ABC.

differs from the substring in Java classes:

substring (int beginindex, int endindex): Starts at the specified beginindex, ends at the specified endIndex-1, and the first position in the string is always 0. Endindex, optionally, returns the character that starts at the specified index by default until the end of the string.

For example: "Unhappy". SUBSTRING (2) returns "Happy"

"Hamburger". Substring (3,8) returns "Burge"

The above mentioned is the entire content of this article, I hope you can enjoy.

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.