9

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.

3
  • 4
    "not working" is a very poor description of what happens. Are you getting an error message (what error message), does it crash, does it run but return the wrong result... Please be more specific. Commented Aug 16, 2011 at 17:19
  • This is pretty basic SQL, I don't want to be nasty but surely a quick google of "Oracle SQL concatenation operator" would have given you the answer you needed far faster than posting a question on here? Commented Aug 17, 2011 at 10:46
  • maybe but now it is faster for everyone else to check here Commented Mar 30, 2015 at 5:33

2 Answers 2

22

In Oracle it's:

SELECT column1, 'ABC' || Lic_num
FROM TABLE_ONE
Sign up to request clarification or add additional context in comments.

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.