随笔

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')--执行函数

原文地址:https://www.cnblogs.com/xiaowangtongxue123/p/13264780.html