xml
  1. xml-string-concat

XML String concat()

The concat() function in XQuery is used to concatenate two or more strings and returns a new string.

Syntax

The syntax for the concat() function is as follows:

concat(string1, string2, ..., stringN)

Where:

  • string1, string2, ..., stringN are the strings to be concatenated.

Example

let $str1 := "Hello"
let $str2 := "World"
return concat($str1, " ", $str2, "!")

Output

Hello World!

Explanation

In the example above, we declare two variables $str1 and $str2 with the values Hello and World respectively. We then use the concat() function to concatenate the two strings along with a space and an exclamation mark to create the output string Hello World!.

Use

The concat() function is typically used when you need to combine multiple strings to form a single string, such as when building dynamic queries or constructing messages.

Important Points

  • The concat() function takes two or more strings as input parameters.
  • The function returns the concatenated string.
  • If any of the input strings is empty, the function returns the concatenation of the other non-empty strings.
  • If all input strings are empty, the function returns an empty string.

Summary

In this tutorial, we learned about the concat() function in XQuery, which is used to concatenate two or more strings. We also looked at the syntax, example, output, explanation, use, and important points of this function.

Published on: