Concatenation Operator in Oracle

•The concatenation operator concatenates operands.

•This operator is expressed by (double vertical lines) ||.

•This operator operates on character strings and CLOB datatype.

•This operator behaves as following way,

If both operands are of datatype CHAR, the result holds CHAR datatype and is limited to 2000 characters. If either string has datatype VARCHAR2, the result holds datatype VARCHAR2 and is limited to 4000 characters. If either operand is has datatype CLOB, the result become temporary CLOB.

•Trailing or leading blanks are preserved by this operator. Example:
SQL> select ' ' || 'test' from dual;
''||'TEST'
-----------------
test

SQL> select length(' ' || 'test ') from dual;

LENGTH(''||'TEST')
------------------
18

•Instead of || the CONCAT function also be used for concatenation.

Example:
-----------------
SQL> create table test_concat(col1 varchar2(10), col2 varchar2(30));

Table created.

SQL> insert into test_concat values('Shaik','China India Usa');

1 row created.

SQL> select concat(col1,col2) from test_concat;
CONCAT(COL1,COL2)
----------------------------------------
Shaik china India Usa

SQL> select col1||col2 from test_concat;
COL1||COL2
----------------------------------------
Shaik china India Usa

SQL> select col1||'-'||'Three Countries: '||col2 from test_concat;
COL1||'-'||'THREECOUNTRIES:'||COL2
----------------------------------------------------------
Shaik-Three Countries: Shaik china India Usa

Comments

Popular posts from this blog

How to make partitioning in Oracle more Quickly

Copy files between Unix and Windows with rcp

ORA-04062: timestamp of procedure has been changed