Suppose there's a column value:
235698752
How do I break it like:
2 3569 8752
How ca开发者_JS百科n this be done in a SQL statement?
Another option, also for SQL Server:
SELECT STUFF(STUFF('235698752',6,0,' '),2,0,' ')
Here's a shot, not sure if it's exactly what you want:
SELECT '[' + CAST(235698752 as char(10)) + ']'
, SUBSTRING(CAST(235698752 as char(10)),1,1)
, SUBSTRING(CAST(235698752 as char(10)), 4,4)
, SUBSTRING(CAST(235698752 as char(10)), 6,4)
, SUBSTRING(CAST(235698752 as char(10)), 6,4)
The same thing, in Oracle SQL using SUBSTR
SELECT
SUBSTR('235698752',1,1) || ' ' ||
SUBSTR('235698752',2,4) || ' ' ||
SUBSTR('235698752',6,4)
from dual;
Note this assumes a length of 9 for the number.
精彩评论