This post will discuss the following content:
- Using “||” Operator to Concatenate Data in Oracle SQL Developer
- Using CONCAT() Function to Concatenate in Oracle SQL Developer
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”:
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:
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:
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:
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:
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:
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:
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.