Def snx (prefix: str, width: int):
..... "Returns the specified prefix+fixed-length self-increasing serial number"
....idx=0
....fmt = ' { } { {:0 & gt; {}}'. Format (prefix, width)
... and idx< 10 ** width:
..... output fmt.format(idx)
........idx = idx + 1
sn4 = snx(' 138 12 12 ',4)
Print (Next (sn4))? #? 138 12 120000
Print (Next (sn4))? #? 138 12 12000 1
If generality is not considered, only list expressions can be used:
phone _ numbers =[' 138 12 12 {:0 & gt; 4}'. Format of I in the range (10000)]
SQL, there is no iterator, and there is no such good string formatting, so it can only be a little troublesome:
declare @idx int = 0
while @ idx & lt 10000
begin
print(' 138 12 12 '+right(replicate(' 0 ',4) + convert(varchar(4),@idx),4))
select @idx = @idx + 1
end