需求:将字段中字符串值包含的大写B替换为小写的a
方法一、
- Update 表 Set 字段 = REPLACE(字段,'B' COLLATE Latin1_General_CS_AS, 'a')
复制代码
方法二、
- CREATE FUNCTION [dbo].[ReplaceLetter]
- ( @String VARCHAR(100),@StringSingle VARCHAR(1),@StringReplaceMent VARCHAR(100) )
- RETURNS VARCHAR(100)
- AS
- BEGIN
- DECLARE @Position INT = 1;
- DECLARE @Character VARCHAR(1);
- DECLARE @NewCharacter VARCHAR(100);
- SET @NewCharacter = ''
- WHILE @Position <= Len( @String )
- BEGIN
- SET @Character = Substring( @String, @Position, 1 );
- SELECT
- @NewCharacter = @NewCharacter
- + CASE
- WHEN Ascii( @Character ) <> Ascii( @StringSingle ) THEN @Character
- ELSE @StringReplaceMent
- END
- SET @Position = @Position + 1;
- END
- RETURN @NewCharacter;
- END
- GO
复制代码
|
|
快表帝国客服01