concat_ws
This function is used to return a string concatenated from multiple input strings that are separated by specified separators.
Syntax
concat_ws(string <separator>, string <str1>, string <str2>[,...])
or
concat_ws(string <separator>, array<string> <a>)
Returns the result of joining all the strings in the parameters or the elements in an array using a specified separator.
Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
separator |
Yes |
STRING |
Separator of the STRING type |
str1, str2 |
Yes |
STRING |
At least two strings must be specified. The value is of the STRING type. If the value is of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the value is implicitly converted to the STRING type for calculation. |
a |
Yes |
ARRAY |
The elements in an array are of the STRING type. |
Return Values
The return value is of the STRING or STRUCT type.
![](https://support.huaweicloud.com/intl/en-us/sqlreference-dli/public_sys-resources/note_3.0-en-us.png)
- If the value of str1 or str2 is not of the STRING, BIGINT, DECIMAL, DOUBLE, or DATETIME type, an error is reported.
- If the value of the parameter (string to be concatenated) is NULL, the parameter is ignored.
- If there is no input parameter (string to be concatenated), NULL is returned.
Example Code
- Use a colon (:) to connect strings ABC and DEF. An example command is as follows:
- The value of any input parameter is NULL. An example command is as follows:
The value avg:18 is returned.
select concat_ws(':','avg',null,'18');
- Use colons (:) to connect elements in the array ('name', 'lilei'). An example command is as follows:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot