Is there a way to have a common operator for concatenation in Oracle, Postgres and SQL Server.
In Oracle and Postgres we use ||
and SQL Server uses +
.
I've solved the problem in Postgres by adding the custom operator +
to support string concatenation.
Is there a way to add the same operator in Oracle to support string concatenation using the +
operator.
The concatenation operator is the plus sign (+). You can combine, or concatenate, two or more character strings into a single character string. You can also concatenate binary strings.
Concatenation operator || In addition to the CONCAT() function, Oracle also provides you with the concatenation operator ( || ) that allows you to concatenate two or more strings in a more readable fashion: string1 || string2 || string3 || ...
Concatenation can only be used with character strings. Strings are concatenated by placing the concatenation operator (||) between two or more character strings (string literal or a character string variable) that you wish to be combined.
||
is the SQL Standard concatenation operator (see SQL 2008: 5.2). Use that, and complain if it doesn't work in the system you're using ;-)
Seriously though, you should make other systems use ||
, not +
. Not only is it more standard, but it's easier to accidentally cause confusion if you use +
, especially if any types have to be inferred or and implicit casts are happening.
Consider: '5' + 2
If the system you're using doesn't throw an error on that one, and +
means both plus and concatenation, you might be in for some confusing results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With