SQL String Functions

Source: Internet
Author: User

1. Convert to uppercase String upper

The upper function is used to return all strings to uppercase characters.

return value:

varchar or nvarchar, variable-length string.

Example:

Select Upper (' ABCDEFG ')    --output ABCDEFG Notice that it's all converted to uppercase.

 

2. Convert to lowercase string lower

The lower function returns after all the strings have been converted to lowercase characters.

return value:

varchar or nvarchar, variable length string

Example:

Select lower (' ABCDEFG ')    --The output ABCDEFG has all been converted to lowercase

3. Clear the left space LTrim

If the character of a string is a space, the LTrim function is used to clear contiguous left spaces.

varchar or nvarchar, variable-length string.

Example:

Select LTrim ('    123456789 ')  --output 123456789, note that the left-hand space has been deleted, the output string to the left is no space

 

4. Clear the right space RTrim

The RTrim function is used to empty contiguous spaces on the right.

varchar or nvarchar, variable-length string.

Example:

Select RTrim (' 123456789   ')    --output 123456789, note that the right space has been cleared

 

5. Intercept string substring

The SUBSTRING function can intercept strings in a string.

Example:

Select substring (' Hello ')    --Output He     is a little different from C #, and its first character starts with 1.

6. Get the string length len

The Len function is used to get the length (number of characters) of a string, but does not include the right space. The left space and the space on the right are counted.

   

Example:

Select Len (' The big, all the world ')    --Output 9

 

 14. Truncate left string

The left function is used to intercept a string of the specified length, starting with the first character on the other. Its execution effect equals substring (expression,1,length)

varchar or nvarchar, variable-length string.

Example:

Select Left (' 123456789 ', 3)    --Output 123

   15. Truncate RIGHT string

The right function is used to intercept a string of the specified length starting with the first character on the left. Its execution effect equals sunstring (Expression,len (expression)-length+1,length).

varchar or nvarchar, variable-length string.

Example:

Select Right (' 123456789 ', 3)    --Output 789

   16. Clear the left space LTrim

If the character of a string is a space, the LTrim function is used to clear contiguous left spaces.

varchar or nvarchar, variable-length string.

Example:

Select LTrim ('    123456789 ')  --output 123456789, note that the left-hand space has been deleted, the output string to the left is no space

  17. Clear the right space RTrim

The RTrim function is used to empty contiguous spaces on the right.

varchar or nvarchar, variable-length string.

Example:

Select RTrim (' 123456789   ')    --output 123456789, note that the right space has been cleared

  23. REPLACE

Replaces all occurrences of the specified string value with another string value.

Example:

SELECT replace (' ABCDE ', ' abc ', ' xxx ')    --xxxde     ABCDE is going to look for those characters (ABCDE)   ABC is going to replace the ABC    XXX is to replace what

SQL String Functions

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.