Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL, concatenate multiple columns + add text

People also ask

How do I concatenate two columns in select query in Oracle?

Oracle String concatenation allows you to append one string to the end of another string. To display the contents of two columns or more under the name of a single column, you can use the double pipe concatenation operator (||).

How do I concatenate in Oracle SQL?

There are two ways to concatenate Strings in Oracle SQL . Either using CONCAT function or || operator. SELECT CONCAT( string1, string2 ) FROM dual; Since CONCAT function will only allow you to concatenate two values together.

How do I add a space in concatenate in Oracle?

We can concatenate a space character using the || operator. In this example, we have used the || operator to add a space character between the values Dave and Anderson. This will prevent our values from being squished together.


You have two options for concatenating strings in Oracle:

  • CONCAT
  • Using ||

CONCAT example:

CONCAT(
  CONCAT(
    CONCAT(
      CONCAT(
        CONCAT('I like ', t.type_desc_column), 
        ' cake with '), 
      t.icing_desc_column),
    ' and a '),
  t.fruit_desc_column)

Using || example:

'I like ' || t.type_desc_column || ' cake with ' || t.icing_desc_column || ' and a ' || t.fruit_desc_column

Did you try the || operator ?

Concatenation Operator Documentation from Oracle >>>


select 'i like' || type_column || ' with' ect....

Below query works for me @Oracle 10G ----

select PHONE, CONTACT, (ADDR1 ||  '-' || ADDR2 || '-' || ADDR3) as Address
from CUSTOMER_DETAILS
where Code='341'; 

O/P -

1111 [email protected] 4th street-capetown-sa


The Oracle/PLSQL CONCAT function allows to concatenate two strings together.

CONCAT( string1, string2 )

string1

The first string to concatenate.

string2

The second string to concatenate.

E.g.

SELECT 'I like ' || type_column_name || ' cake with ' || 
icing_column_name || ' and a ' fruit_column_name || '.' 
AS Cake FROM table;

Try this:

SELECT 'I like ' || type_column_name || ' cake with ' || 
icing_column_name || ' and a ' fruit_column_name || '.' 
AS Cake_Column FROM your_table_name;

It should concatenate all that data as a single column entry named "Cake_Column".