Oracle Database

How do I Concatenate in Oracle SQL Developer?

Concatenation is utilized to join multiple strings together to form a single string and return it under the name of a single column. It displays the data needed in a more streamlined and structured manner. While working with Oracle databases using Oracle SQL Developer, it is essential to learn about concatenation. It generates more concise and informative query results. However, Oracle provides an operator and even a function to perform concatenation easily.

This post will discuss the following content:

Method 1: Using “||” Operator to Concatenate Data in Oracle SQL Developer

In Oracle SQL Developer, the concatenation operator is represented by the double vertical bar “||” symbol. It is utilized to join two or more strings or columns together to form a single string. However, the resulting concatenated string can be utilized in the “SELECT” statement or any other SQL statement to return the desired result.

Let us see some examples of concatenation using the operator:

Example 1: Simple Concatenation Using “||” Operator

Here is an example of using the concatenate operator to join two columns. First, let us run the command given below to display the table “REGIONS”:

SELECT * FROM REGIONS;

Output

The output depicts the data of the “REGIONS” table including the “REGION_ID” and “REGION_NAME” columns.

Execute this command to concatenate values of the “REGION_ID” and “REGION_NAME” columns using the concatenate operator into a single string:

SELECT REGION_ID || ' ' || REGION_NAME AS REGION FROM REGIONS;

Output

The above output returns a column named “REGION” containing the values of the “REGION_ID” and “REGION_NAME” columns along with a space in between.

Example 2: Concatenation Based on a Condition Using Operator

The user can perform concatenation based on a condition by using the “WHERE” clause with the concatenation operator. For this example, first display the “COUNTRIES” table by executing the following command:

SELECT * FROM COUNTRIES;

Output

The output has provided the “COUNTRIES” table having the “COUNTRY_ID“, “COUNTRY_NAME“, and “REGION_ID” columns.

Let us concatenate the values of the “COUNTRY_ID” and “COUNTRY_NAME” columns only for the countries where the “REGION_ID” is greater than “1”, type this command:

SELECT COUNTRY_ID || ',' || COUNTRY_NAME AS COUNTRY FROM COUNTRIES WHERE REGION_ID > 1;

Output

The output has returned a column named “COUNTRY” that contains the concatenated values that meet the specified condition.

Method 2: Using CONCAT() Function to Concatenate in Oracle SQL Developer

Oracle also offers functions for concatenation, such as the CONCAT() function which is most used in Oracle SQL Developer for concatenation.

Let us see some examples of concatenation using the CONCAT() function:

Example 1: Simple Concatenate Using CONCAT() Function

Here is an example that uses the CONCAT() function to join two columns. But before that let us execute this command to display the “CUSTOMERS” table that will be used in this example:

SELECT * FROM CUSTOMERS;

Output

The above output has displayed the data of the “CUSTOMERS” table.

To use the CONCAT() function to join the values of the “CUSTOMER_ID” and “WEBSITE” columns, execute the below command:

SELECT CONCAT(CUSTOMER_ID , WEBSITE) AS DETAIL FROM CUSTOMERS;

Output

The output has returned to the desired output after concatenation.

Example 2: Nested Concatenate Using CONCAT() Function

The CONCAT() function can be utilized inside another CONCAT() function to combine more than two strings or add a separator between them and form a single string.

Let us execute the below command to concatenate the values of the “CUSTOMER_ID” and “WEBSITE” columns and add a comma and a space between them:

SELECT CONCAT(CONCAT(CUSTOMER_ID,' , '), WEBSITE) as DETAIL FROM CUSTOMERS;

Output

The output depicted the result after concatenating the values in the “CUSTOMER_ID” and “WEBSITE” columns and adding a comma and a space between them in the column named “DETAIL“.

Conclusion

In Oracle SQL Developer, concatenation is utilized to join two or more strings or columns into a single string via the concatenation “||” operator or CONCAT() function. Both these methods are used to concatenate data in Oracle SQL Developer. The user can perform concatenation based on a condition by using the “WHERE” clause. This post has demonstrated how to concatenate data in Oracle SQL Developer using the “||” operator and the CONCAT() function.

About the author

Nimrah Ch

I’m a technical writer with a Bachelor's in Software Engineering and Certification in Cyber Security. Through my research and writing, I strive to provide readers with in-depth, informative articles that can help them make informed decisions about their technological needs.