DECLARE @tNameTable TABLE(name VARCHAR(10))
--insert data
INSERT INTO @tNameTable
VALUES('唐三')
INSERT INTO @tNameTable
VALUES('唐三藏')
INSERT INTO @tNameTable
VALUES('唐朝盛世')
SELECT * FROM @tNameTable
-- start to mark
SELECT CASE LEN(name)
WHEN 0 | 1
THEN ''
WHEN 2 THEN CONCAT(LEFT(name, 1),'O')
ELSE
CONCAT(LEFT(name,1),SUBSTRING('OOOOOOOOOO',1,LEN(name)-2),RIGHT(name,1))
END
FROM @tNameTable
結果!!!
預設的資料是 唐三,唐三藏,唐朝盛世
經過馬賽克字串處理會變成 唐O,唐O藏,唐OO世