Concatenate (||)
The ||
operator makes a string
concatenation.
Syntax
expr || expr
- expr can be a character, numeric or date/time expression.
Usage
The ||
operator is the concatenation operator that produces a string expression
from the expression elements on both sides of the operator.
If any of the members of a concatenation expression is NULL
, the result string
will be NULL
.
The ||
operator is typically used to concatenate strings to build a value passed
as parameters to a function.
||
concatenation operator has different formatting rules as the comma concatenation operator. The comma will do fixed-size
formatting for numeric and date/time values, while ||
will trim the values. The ||
operator has a lower precedence than arithmetic operators; For example,
a || b + c
is equivalent to (a||(b+c))
.
However, the ||
operator has a higher precedence than LIKE
, MATCHES
and USING
operators; For example, v
USING "&&" || "&"
is equivalent to v USING ("&&" ||
"&")
which is the same as v USING "&&&"
.
Example
Building strings to be passed as parameters to functions:
MAIN
CALL print_message( 5, "Current date: " || TODAY )
DISPLAY "Length: ", length( "ab" || "cdef" )
END MAIN
FUNCTION print_message(l TINYINT, s STRING)
DISPLAY "Level: ", l, " ", s
END FUNCTION
Level: 5 Current date: 12/22/2018
Length: 6
MAIN
DISPLAY 78 || 1 + 8 -- 789
DISPLAY 78 || 3 * 3 -- 789
DISPLAY 789 USING "&&" || "&" -- 789
DISPLAY (34 USING "&&") || "&" -- 34&
DISPLAY "abc" MATCHES "ab" || "c" -- 1 (TRUE)
DISPLAY ("ab" MATCHES "ab") || "c" -- 1c
DISPLAY "a" MATCHES "a" || "&&" -- 0 (FALSE)
DISPLAY 23 USING "a" MATCHES "a" || "&&" -- * (format = "0")
DISPLAY 23 USING ("a" MATCHES "a") || "&&" -- 123
END MAIN
||
and ,
(comma):MAIN
DISPLAY "Date: ", TODAY, " day num: ", DAY(TODAY), " Pi=", 3.1415
DISPLAY "Date: "||TODAY||" day num: "||DAY(TODAY)||" Pi="||3.1415
END MAIN
Date: 12/22/2018 day num: 22 Pi= 3.1415
Date: 12/22/2018 day num: 22 Pi=3.1415