1

I don't understand why these two code results are identically the same? I thought if I have quotes it just concatenate strings. Why not first one is 300.5100? I know second one is 400.5 anyway. Thank you

Select to_char('300.5' + '100') From Dual;

Select to_char(300.5 + 100) From Dual;

2 Answers 2

4

To concatenate strings in SQL you have to use ||. The + is only there to add numbers. If you didn't pass '300.5' + '100' you would simply get an error, e.g. the following is invalid SQL:

select '300.5' + '100'
from dual;

But as to_char() expects a number as the input parameter Oracle implicitly converts those strings to numbers and then adds them, just like in the second statement.

Sign up to request clarification or add additional context in comments.

Comments

3

concatenation is

'xxx' || 'yyy'

your example allows the literals to be converted to numeric then treated as normal numbers.

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.