随笔

go
create function dbo.Replacestr(@stringstr nvarchar(50),@selectstr nvarchar(50),@replacstr nvarchar(50))--参数
returns nvarchar(50)--返回值
as
begin
--定义变量接受返回值
declare @str nvarchar(50);
if(@stringstr = '')
begin
--带替换字符串为空时提示
set @str = '待替换字符串不能为空!';
end
else
begin
--执行替换函数
set @str = REPLACE(@stringstr,@selectstr,@replacstr);
end
--返回
return @str
end

go
select dbo.Replacestr('','f','123')--执行函数

posted @ 2020-07-08 08:13  小王同学123  阅读(96)  评论(0编辑  收藏  举报