I'm doing a query in an Oracle database and I come across this || '-' ||
symbology in my query . Would you like to know the meaning?
Select
xf0cdloc || '-' || XN4CDEMP AS LOCOMOTIVA,
From
Trem
I'm doing a query in an Oracle database and I come across this || '-' ||
symbology in my query . Would you like to know the meaning?
Select
xf0cdloc || '-' || XN4CDEMP AS LOCOMOTIVA,
From
Trem
In Oracle and Postgres the two pipes ( ||
) are the concatenation operator.
MySQL by default does not use an operator but a function, concat ( ) however it is possible to change it through pipes changed the value of variable sql_mode
to PIPES_AS_CONCAT
SELECT 'teste' || 'algo'
Returns a column by concatenating the two values.
What your code is doing is selecting two columns from the Trem
, xf0cdloc
, and XN4CDEMP
tables, and you are building a virtual column that will only exist in that query. This virtual column calls LOCOMOTIVA
and its content is the concatenation of the contents of xf0cdloc
after a dash ( '-'
) and then it already glues the contents of XN4CDEMP
.
The ||
is the concatenation operator. It is defined in the standard SQL specification. But some database systems do not implement it, so this syntax may not work depending on where you use it. Because of this some people recommend using CONCAT()
when you want the code to be portable to other systems.
In other systems or other languages would be the equivalent of doing this:
Select
xf0cdloc + '-' + XN4CDEMP AS LOCOMOTIVA,
From
Trem