Introduction to SQL function substr, SQL function substr

Source: Internet
Author: User

Introduction to SQL function substr, SQL function substr

Interpretation of the substr (string, 1, 3) function: returns a string with a length of three characters from left to right.

Result: str

From right to left?

There should be another function to provide such a function!

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

Interpretation of the substr (String,-) function: Take the first digit on the right of the string and start taking three digits.

Result: g

Substr (string, start, length)

String-specifies the string to be truncated.
Start-required, specifying where the string starts. Positive number-start at the specified position of the string, negative number-start at the specified position from the end of the string, and 0-Start at the first character of the string.
Length-(optional) specifies the length of the string to be truncated. If the length is short, all characters before the end of the character expression value are returned.

For example, select substr ('abcdefg', 3,4) from dual; the result is cdef.
Select substr ('abcdefg',-3,4) from dual; Result efg

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

For example: select substr ('abcdefg',) from dual; the result is abc.

Select substr ('abcdefg',) from dual; the result is abc.

Difference from substring in java class:

Substring (int beginIndex, int endIndex): starts from the specified beginIndex and ends at the specified endIndex-1. The first position in the string is always 0. EndIndex (Optional). It returns the characters starting from the specified index until the end of the string.

Example: "unhappy". substring (2) returns "happy"

"Hamburger". substring (3,8) returns "burge"

The above is all the content of this article. I hope you will like it.

Related Article

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.