gpt4 book ai didi

sql - 如何从 T-SQL 中的字符串中删除扩展 ASCII 字符?

转载 作者:行者123 更新时间:2023-12-02 09:47:53 25 4
gpt4 key购买 nike

我需要从 T-SQL 中的 SELECT 语句中过滤(删除)扩展 ASCII 字符。

我正在使用存储过程来执行此操作。

预期输入:

ËËËËeeeeËËËË

预期输出:

eeee

我找到的所有内容都是 MySQL .

我正在使用:

Microsoft SQL Server Management Studio  11.0.2100.60
Microsoft .NET Framework 4.0.30319.17929

最佳答案

好的,尝试一下。他们似乎有同样的问题。无论如何,您需要根据您的要求对其进行修改。

CREATE FUNCTION RemoveNonASCII 
(
@nstring nvarchar(255)
)
RETURNS varchar(255)
AS
BEGIN

DECLARE @Result varchar(255)
SET @Result = ''

DECLARE @nchar nvarchar(1)
DECLARE @position int

SET @position = 1
WHILE @position <= LEN(@nstring)
BEGIN
SET @nchar = SUBSTRING(@nstring, @position, 1)
--Unicode & ASCII are the same from 1 to 255.
--Only Unicode goes beyond 255
--0 to 31 are non-printable characters
IF UNICODE(@nchar) between 32 and 255
SET @Result = @Result + @nchar
SET @position = @position + 1
END

RETURN @Result

END
GO

查看SqlServerCentral

关于sql - 如何从 T-SQL 中的字符串中删除扩展 ASCII 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15259622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com