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;
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, eg 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.
concatenation is
'xxx' || 'yyy'
your example allows the literals to be converted to numeric then treated as normal numbers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.