The most common truncation functions are left, right, and substring.

Source: Internet
Author: User

The most common truncation functions are left, right, and substring.

1. LEFT (character_expression, integer_expression)

Returns the specified number of characters starting from the left of the string.

 

Example: left ("field name", intercepting strings)

The following example uses the LEFT function to return the leftmost two characters of the abcdefg string.

Select left ('abcdefg', 2) GO

The following is the result set:

-- AB

 

2. RIGHT (character_expression, integer_expression)

Returns the number of integer_expression characters starting from the right.

Example: RIGHT ("field name", intercepting strings)

The following example uses the right function to return the rightmost 2 characters of the abcdefg string.

SELECT right ('abcdefg', 2) GO

The following is the result set:

-- Fg

 

Take 0008

SELECT left (right ('2014-001-0008-A ', 6), 4)

 

 

3. SUBSTRING (expression, start, length)

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

Example: SUBSTRING ("field name", starting from the nth digit, intercepting several strings)

Displays the second, third, and fourth characters in the string constant abcdef.

SELECT x = SUBSTRING ('abcdef', 2, 3)

The following is the result set:

X ---------- bcd

The most common truncation functions are left, right, and 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.