'Oracle appending string to a select statement

I have a column in a oracle table Lic_num char(7 byte)

SELECT column1, 'ABC' + Lic_num
FROM TABLE One

I wanted ABC appended to all the rows that are returned with lic_num appended to it.

I tried tha above query and it is not working.



Solution 1:[1]

In Oracle it's:

SELECT column1, 'ABC' || Lic_num
FROM TABLE_ONE

Solution 2:[2]

This would be the way of doing it.

SELECT column1, 'ABC' || Lic_num FROM TABLE_ONE;
SELECT CONCAT(CONCAT(column1, 'ABC'), Lic_num) FROM TABLE_ONE;

If you need you can rename the concatenated Column name using AS keyword so it would be meaningful in terms of reporting.

Below info is included to help someone looking at concatenation in detail.

There are two ways to concatenate Strings in Oracle SQL. Either using CONCAT function or || operator.

CONCAT function allows you to concatenate two strings together

SELECT CONCAT( string1, string2 ) FROM dual;

Since CONCAT function will only allow you to concatenate two values together. If you want to concatenate more values than two, you can nest multiple CONCAT function calls.

SELECT CONCAT(CONCAT('A', 'B'),'C') FROM dual;

An alternative to using the CONCAT function would be to use the || operator

SELECT 'My Name' || 'My Age' FROM dual;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Codo
Solution 2 Du-Lacoste