SQL string processing functions

Source: Internet
Author: User
Tags rtrim

1: replace Function
The first parameter is your string, the second parameter is what you want to replace, and the third parameter is what you want to replace
Select Replace ('lihan', 'A', 'B ')

-----------------------------
Lihbn

(The number of affected rows is 1)
========================================================== ========================
2: substring function (in SQL Server 2005)
The first parameter is your string, the second parameter is the start position, and the third parameter is the length of the character you want to obtain! The first character is 1, not 0

Select substring ('lihan', 1, 3 );
-----
Lih

(The number of affected rows is 1)
========================================================== ========================
3: charindex Function
The first parameter is the char to be searched for, the second parameter is the string to be searched for, and the third parameter is the position from which to start searching.
Select charindex ('A', 'lihan', 1)
-----------
4

(The number of affected rows is 1)

========================================================== ==============================
4: ASCII Functions
Returns the ASCII code value of the leftmost character in a character expression.
Select ASCII ('lihan ')
-----------
108

(The number of affected rows is 1)

========================================================== ======================================
5: nchar Function
Returns Unicode characters with the specified integer code according to the definition of the Unicode standard.
The parameter is a positive integer between 0 and 65535. If a value out of this range is specified, null is returned.
Select nchar (1, 3213)
----
Unicode characters

(The number of affected rows is 1)

========================================================== ========================
6: soundex
Returns a code (soundex) consisting of four characters to evaluate the similarity between two strings.
Select soundex ('lihan'), soundex ('lihon ');
----------
L546 l542

(The number of affected rows is 1)
========================================================== ========================
7: Char
The parameter is an integer between 0 and 255. If this integer expression is not in this range, null is returned.
Select char (1, 125)
----
}

(The number of affected rows is 1)

========================================================== ============================
8: Str Function
The first parameter must be a number, and the second parameter indicates the position converted to the char type. If it is less than the first parameter, the return value * is greater than the right alignment.
Select STR (12345, 3)
----
***

(The number of affected rows is 1)

Select STR (12345, 12)
------------
12345

(The number of affected rows is 1)
========================================================== ==============================
9: difference function
Returns an integer indicating the difference between the soundex values of two character expressions.
The returned integer is the number of identical characters in the soundex value. The returned values range from 0 to 4. 0 indicates that the values are almost different or completely different. 4 indicates that the values are almost identical or identical.
Select difference ('lihan', 'liha ')
-----------
3

(The number of affected rows is 1)

========================================================== ======================================
10: Stuff function (four parameters)
The function inserts a string into another string. It deletes characters of the specified length from the start position in the first string, and inserts the second string into the start position of the first string.
Select stuff ('lihan', 2, 3, 'lihan ')
--------
Llihann

(The number of affected rows is 1)
========================================================== ======================================

11: Left Function
Returns n leftmost characters, determined by the Parameter
Select left ('lihan', 4)
-----
Liha

(The number of affected rows is 1)
========================================================== ======================================

12 right Function
Returns n characters on the rightmost side, determined by the Parameter
Select right ('lihan', 4)
-----
IHAN

(The number of affected rows is 1)
========================================================== ======================================

13: Replicate Function
In my opinion, the parameter is copied twice.
Select replicate ('lihan', 4)
--------------------
Lihanlihanlihanlihan

(The number of affected rows is 1)

========================================================== ======================================

14: Len Function
Response parameter length
Select Len ('lihan ')
-----------
5

(The number of affected rows is 1)

========================================================== ======================================
15: reverse function
Reverse string
Select reverse ('lihan ')
-----
Nahil

(The number of affected rows is 1)

========================================================== ======================================

16: Lower and Upper Functions
Case-insensitive parameter conversion
Select lower (upper ('lihan '))
--------------------
Lihan

(The number of affected rows is 1)

========================================================== ======================================

17: ltrim and rtrim Functions
Delete spaces on the left and right
Select ltrim ('lihan ')
--------------------------
Lihan

(The number of affected rows is 1)
Select rtrim ('lihan ')
---------
Lihan

(The number of affected rows is 1)

 

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.