开发者

How to break numbers in SQL?

开发者 https://www.devze.com 2023-02-17 01:46 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消