String functions for T-SQL
This topic provides reference information about string function compatibility when migrating from Microsoft SQL Server 2019 to Amazon Aurora MySQL. You can use this guide to understand the similarities and differences in string manipulation capabilities between the two database systems.
Feature compatibility | AWS SCT / AWS DMS automation level | AWS SCT action code index | Key differences |
---|---|---|---|
|
|
N/A |
Differences with the UNICODE paradigm. For more information, see Collations. Syntax and option differences. |
SQL Server Usage
String functions are typically scalar functions that perform an operation on string input and return a string or a numeric value.
Syntax and Examples
The following table lists the most commonly used string functions.
Function | Purpose | Example | Result | Comments |
---|---|---|---|---|
|
Convert an ASCII or UNICODE character to its ASCII or UNICODE code. |
|
65 |
Returns a numeric integer value. |
|
Convert between ASCII or UNICODE code to a string character. |
|
'A' |
Numeric integer value as input. |
|
Find the starting position of one string expression (or string pattern) within another string expression. |
|
2 |
Returns a numeric integer value. |
|
Combine multiple string input expressions into a single string with, or without, a separator character (WS). |
|
'ab', 'a,b' |
|
|
Return a partial string from another string expression based on position and length. |
|
'ab', 'bc' |
|
|
Return a string with all characters in lower or upper case. Use for presentation or to handle case insensitive expressions. |
|
'abcd' |
|
|
Remove leading and trailing spaces. |
|
'abc d ' |
|
|
Convert a numeric value to a string. |
|
3.142 |
Numeric expressions as input. |
|
Return a string in reverse order. |
|
'dcba' |
|
|
Return a string that consists of zero or more concatenated copies of another string expression. |
|
'abcabcabc' |
|
|
Replace all occurrences of a string expression with another. |
|
'axyd' |
|
|
Parse a list of values with a separator and return a set of all individual elements. |
|
1 2 |
|
|
Return a string that consists of concatenated string values in row groups. |
|
1 'ab' 2 'c' |
|
For more information, see String Functions (Transact-SQL)
MySQL Usage
Amazon Aurora MySQL-Compatible Edition (Aurora MySQL) supports a large set of string functions; far more than SQL Server. See the link at the end of this section for the full list. Some of the functions, such as regular expressions (REGEXP
), don’t exist in SQL Server and may be useful for your application.
Syntax and Examples
The following table lists the most commonly used string functions.
Function | Purpose | Example | Result | Comments |
---|---|---|---|---|
|
Convert an ASCII or multi-byte code to its string character. |
|
65 |
Returns a numeric integer value. |
|
Convert between a character and its UNICODE code. |
|
'A' |
Numeric integer value as input. |
|
Find the starting position of one string expression (or string pattern) within another string expression. |
|
2 |
Returns a numeric integer value. |
|
Combine multiple string input expressions into a single string with or without a separator character (WS). |
SELECT CONCAT ('a','b'), CONCAT_WS(',','a','b') |
'ab', 'a,b' |
|
|
Return a partial string from another string expression based on position and length |
|
'ab', 'bc' |
|
|
Return a string with all characters in lower or upper case. Use for presentation or to handle case insensitive expressions. |
|
'abcd' |
These have no effect when applied to binary collation strings. Convert the string to a non-binary string collation to convert letter case. |
|
Remove leading and trailing spaces. |
|
'abc d ' 'abcxxx' |
|
|
Convert a numeric value to a string. |
|
3.14159 |
Numeric expressions as input. |
|
Return a string in reverse order. |
|
'dcba' |
|
|
Return a string that consists of zero or more concatenated copies of another string expression. |
SELECT REPEAT('abc', 3) |
'abcabcabc' |
|
|
Replace all occurrence of a string expression with another. |
|
'axyd' |
Migration Considerations
Aurora MySQL doesn’t handle ASCII
and UNICODE
types separately. Any string can be either UNICODE
or ASCII
, depending on its collation property. For more information, see Data Types.
Many of the Aurora MySQL string functions that are compatible with SQL Server also support additional functionality. For example, the TRIM
and CHAR
functions. Aurora MySQL also supports many functions that SQL Server doesn’t support. For example, functions that deal with a delimited list set of values. Be sure to explore all options.
Aurora MySQL also supports regular expressions. See the REGEXP
and RLIKE
functions to get started.
Summary
The following table identifies similarities, differences, and key migration considerations.
SQL Server function | Aurora MySQL function | Comments |
---|---|---|
|
|
Compatible. For more information, see Data Types. |
|
|
Unlike SQL Server, |
|
|
Use the |
|
|
Compatible syntax. |
|
|
Compatible syntax. Aurora MySQL supports Use the |
|
|
Compatible syntax. |
|
|
Compatible syntax. The syntax is shown following:
|
|
|
|
|
|
Compatible syntax. |
|
|
Compatible arguments. |
|
|
Compatible syntax. |
|
Not supported. |
Requires iterative code to extract elements with scalar string functions. |
|
Not supported |
Requires iterative code to build a list with scalar string functions. |
For more information, see String Functions and Operators