sqldatabaseoracle-databaseconcatenationoracle-xe

Using string concatenation in Oracle SQL Developer not outputting in desired format


I have a CUSTOMER table and have to concatenate the FirstName and LastName columns seperated by a comma and a space ', ' into one new column called CustomerName.

The desired output is something like:

CustomerName
----------------------
FirstName1, LastName1
FirstName2, LastName2
FirstName3, LastName3

But my actual output is:

CustomerName
----------------------------------------
FirstName1                    , LastName1
FirstName2                    , LastName2
FirstName3                    , LastName3

I have tried nesting the CONCAT function:

SELECT CONCAT(CONCAT(FirstName, ', '),LastName) "CustomerName"
FROM CUSTOMER;

I have also tried using the double pipe concatenation operator (||):

SELECT FirstName ||', '|| LastName "CustomerName"
FROM Customer;

Both Sections of code result in the same output where each column is separated by a lot of whitespace opposed to just a space.


Solution

  • seems like your datatype is just char and not var or alot of space has been saved ,the best would be to chnage your datatype to var,if not you can trim them :

    SELECT TRIM(FirstName) ||', '|| TRIM(LastName)  "CustomerName"
    FROM Customer;