CONCAT_WS
Description
The CONCAT_WS
function is used to concatenate multiple strings or string elements in an array into a single string. The function can concatenate the input strings or string elements in an array based on the specified separator sep
. If an input string is NULL
, it is ignored in the result.
Syntax
Parameters
sep
: Separator string used to join the input strings.str1, str2, ..., strN
: Strings to be joined.array1, array2, ..., arrayN
: Arrays containing string elements to be joined.
Return Result
Returns a concatenated string.
Usage Example
- Basic usage:
Results:
- Connect multiple strings:
Results:
- Ignore
NULL
values:
Results:
- Using Arrays to Concatenate Strings:
Results:
- Use in combination with other functions:
Results:
Notes
- When the input string or array elements are
NULL
, theCONCAT_WS
function will ignore these values. - If all input strings or array elements are
NULL
, an empty string is returned. - If the separator
sep
is alsoNULL
, a NULL is returned.
Through the above examples and explanations, you can better understand the usage and functionality of the CONCAT_WS
function. In practical applications, you can flexibly use this function to concatenate strings or array elements as needed.