34,594
社区成员
发帖
与我相关
我的任务
分享
create function xx(@n varchar(100))
returns table as return
(with cte as
(
select A.number,n,SUBSTRING(n,number,1) as single
from master.dbo.spt_values A
join (select @n as n) as B on number<=LEN(n)
where type='p' and number>0)
select distinct n,(select cast(single as varchar) from cte order by single desc for XML path('')) as new
from cte
)
GO
create procedure xx(@n varchar(100))
as
begin
with cte as
(
select A.number,n,SUBSTRING(n,number,1) as single
from master.dbo.spt_values A
join (select @n as n) as B on number<=LEN(n)
where type='p' and number>0
)
select distinct n,(select cast(single as varchar) from cte order by single desc for XML path('')) as new
from cte
end
你这个函数每次只传入1个字符串,最终的处理结果也是一个字符串,所以可以直接返回字符串,而不用返回表的。上次那么写,是因为为了一个表里的多个字符串同时处理,输出结果也是多个字符串,所以返回的是表。
你说的存储语句是存储过程吗?mysql有些麻烦,首先你可能需要人为创建一张序号表来起到spt_values的作用,还有就是要用group_concat来代替XML path函数进行字符串拼接。
你说的存储语句是存储过程吗?mysql有些麻烦,首先你可能需要人为创建一张序号表来起到spt_values的作用,还有就是要用group_concat来代替XML path函数进行字符串拼接。