Advertisement
Advertisement


What is the string concatenation operator in Oracle?


Question

What is the string concatenation operator in Oracle SQL?

Are there any "interesting" features I should be careful of?

(This seems obvious, but I couldn't find a previous question asking it).

2015/06/29
1
172
6/29/2015 9:28:32 PM

Accepted Answer

It is ||, for example:

select 'Mr ' || ename from emp;

The only "interesting" feature I can think of is that 'x' || null returns 'x', not null as you might perhaps expect.

2014/03/03
237
3/3/2014 10:07:33 AM

There's also concat, but it doesn't get used much

select concat('a','b') from dual;
2008/11/10

I would suggest concat when dealing with 2 strings, and || when those strings are more than 2:

select concat(a,b)
  from dual

or

  select 'a'||'b'||'c'||'d'
        from dual
2016/04/22

DECLARE
     a      VARCHAR2(30);
     b      VARCHAR2(30);
     c      VARCHAR2(30);
 BEGIN
      a  := ' Abc '; 
      b  := ' def ';
      c  := a || b;
 DBMS_OUTPUT.PUT_LINE(c);  
   END;

output:: Abc def

2018/05/14

Using CONCAT(CONCAT(,),) worked for me when concatenating more than two strings.

My problem required working with date strings (only) and creating YYYYMMDD from YYYY-MM-DD as follows (i.e. without converting to date format):

CONCAT(CONCAT(SUBSTR(DATECOL,1,4),SUBSTR(DATECOL,6,2)),SUBSTR(DATECOL,9,2)) AS YYYYMMDD
2020/03/30

Source: https://stackoverflow.com/questions/278189
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]