Why below query is giving output 3 instead of 12? I am concating two characters still why output is number?
select '1' + '2' from dual;
Why below query is giving output 3 instead of 12? I am concating two characters still why output is number?
select '1' + '2' from dual;
In Oracle, + is the addition operator and || is the string concatenation operator.
If you want to concatenate strings then use:
select '1' || '2' from dual;
Which outputs:
| '1'||'2' |
|---|
| 12 |
If you want to add two numbers then use:
select 1 + 2 from dual;
Which outputs:
| 1+2 |
|---|
| 3 |
If you use:
select '1' + '2' from dual;
Then it is implicitly converted to:
select TO_NUMBER('1') + TO_NUMBER('2') from dual;
As the addition operator accepts numeric operands (and not string operands).