XQuery Add
In XQuery, you can perform addition operations on numeric values using the +
operator. The +
operator is used to add two or more numbers together and return the result as a numeric value.
Here are some examples of how to use the +
operator in XQuery:
- Adding Two Numbers:
let $num1 := 10
let $num2 := 20
let $sum := $num1 + $num2
return $sum
Output: 30
In this example, we assigned the values 10 and 20 to the variables $num1
and $num2
, respectively. Then, we added these two variables together using the +
operator and stored the result in the variable $sum
.
- Adding Multiple Numbers:
let $numbers := (5, 8, 12, 3, 7)
let $total := sum($numbers)
return $total
Output: 35
In this example, we have a sequence of numbers stored in the variable $numbers
. We use the sum()
function to calculate the sum of all the numbers in the sequence and store the result in the variable $total
.
- Adding Decimal Numbers:
let $num1 := 3.14
let $num2 := 2.86
let $result := $num1 + $num2
return $result
Output: 6.0
In this example, we added two decimal numbers, 3.14 and 2.86, using the +
operator. The result is a decimal value, which is 6.0
.
The +
operator can be used with various numeric data types, including integers and decimals. It is a straightforward and commonly used operator for performing addition operations in XQuery.