| --- |
| { |
| "title": "CONCAT_WS", |
| "language": "en" |
| } |
| --- |
| |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| ## concat_ws |
| ### Description |
| #### Syntax |
| |
| ```sql |
| VARCHAR concat_ws(VARCHAR sep, VARCHAR str,...) |
| VARCHAR concat_ws(VARCHAR sep, ARRAY array) |
| ``` |
| |
| Using the first parameter SEP as a connector, the second parameter and all subsequent parameters(or all string in an ARRAY) are spliced into a string. |
| If the separator is NULL, return NULL. |
| The `concat_ws` function does not skip empty strings, it skips NULL values. |
| |
| ### example |
| |
| ``` |
| mysql> select concat_ws("or", "d", "is"); |
| +----------------------------+ |
| | concat_ws('or', 'd', 'is') | |
| +----------------------------+ |
| | doris | |
| +----------------------------+ |
| |
| mysql> select concat_ws(NULL, "d", "is"); |
| +----------------------------+ |
| | concat_ws(NULL, 'd', 'is') | |
| +----------------------------+ |
| | NULL | |
| +----------------------------+ |
| |
| mysql> select concat_ws("or", "d", NULL,"is"); |
| +---------------------------------+ |
| | concat_ws("or", "d", NULL,"is") | |
| +---------------------------------+ |
| | doris | |
| +---------------------------------+ |
| |
| mysql> select concat_ws("or", ["d", "is"]); |
| +-----------------------------------+ |
| | concat_ws('or', ARRAY('d', 'is')) | |
| +-----------------------------------+ |
| | doris | |
| +-----------------------------------+ |
| |
| mysql> select concat_ws(NULL, ["d", "is"]); |
| +-----------------------------------+ |
| | concat_ws(NULL, ARRAY('d', 'is')) | |
| +-----------------------------------+ |
| | NULL | |
| +-----------------------------------+ |
| |
| mysql> select concat_ws("or", ["d", NULL,"is"]); |
| +-----------------------------------------+ |
| | concat_ws('or', ARRAY('d', NULL, 'is')) | |
| +-----------------------------------------+ |
| | doris | |
| +-----------------------------------------+ |
| ``` |
| ### keywords |
| CONCAT_WS,CONCAT,WS,ARRAY |