String concatenation is different between databases, so it helps to know which database because you need to know:
- The concatenation method/operator
- If the database handles implicit data type conversion
SQL Server doesn't do implicit conversion of numeric into string values:
SELECT CAST(fooid AS VARCHAR(10)) + ' ' + fooname
...so you need to use CAST (or CONVERT) to explicitly change the data type to a text based data type.
For Oracle & PostgreSQL, use the double pipe to concatenate strings:
SELECT fooid || ' ' || fooname
For MySQL, you can use the CONCAT function:
SELECT CONCAT(fooid, ' ', fooname)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…