Monday, June 21, 2010

concatenating strings in Oracle

Different from SQL, there is a function to concatenate strings in Oracle. Here it is:

Concat(str1, str2) - only two arguments!

For example

Table City_Province

CityName Province
Toronto ON
North York ON

Select Concat (CityName, Province) as City from City_Province;

Results:

TorontoON
NorthYorkON

But, if you want some spaces and commas or stuff like that between the fields (of course you want), you can do this:

Select CityName || ',' || Province as City from City_Province

Results:

Toronto,ON
NorthYork,ON

Much better, isn't it?