with cte as (
select '' as chr, '12345' as rest, 0 as lev
union all
select left(rest, 1), stuff(rest, 1, 1, ''), lev + 1
from cte
where rest <> ''
)
select chr
from cte
where lev > 0;
要插入到现有表中,只需添加 insert 在 select :
with cte as (
select '' as chr, '12345' as rest, 0 as lev
union all
select left(rest, 1), stuff(rest, 1, 1, ''), lev + 1
from cte
where rest <> ''
)
insert into t (c)
select chr
from cte
where lev > 0;
1条答案
按热度按时间bf1o4zei1#
可以使用递归cte:
要插入到现有表中,只需添加
insert
在select
:这是一把小提琴。