Common SQL Functions

Source: Internet
Author: User

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
Selectreplace ('lihan', 'A', 'B ')

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

(The number of affected rows is 1)
========================================================== ========================
2: substring Function
The first parameter is your string, the second parameter is the start position, and the third parameter is the end position.
Selectsubstring ('lihan', 0, 3 );
-----
Li

(The number of affected rows is 1)
========================================================== ========================
3: charindex Function
The first parameter is the char to be searched for, and the second parameter is the string to be searched for. Return parameter 1 at parameter 2.
Select charindex ('A', 'lihan ')
-----------
4

(The number of affected rows is 1)

========================================================== ==============================
4: ASCII Functions
Returns the ASCII code value of the leftmost character in a character expression.
Selectascii ('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.
Selectnchar (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.
Selectsoundex ('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.
Selectchar (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.
Selectstr (12345, 3)
----
***

(The number of affected rows is 1)

Selectstr (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.
Selectdifference ('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.
Selectstuff ('lihan', 2, 3, 'lihan ')
--------
Llihann

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

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

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

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

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

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

(The number of affected rows is 1)

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

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

(The number of affected rows is 1)

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

(The number of affected rows is 1)

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

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

(The number of affected rows is 1)

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

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

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

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.