sqlserver如何判断字段中是否含有汉字?

2025-02-06 10:35:12
推荐回答(4个)
回答1:

--/*

--unicode编码范围:

--汉字:[0x4e00,0x9fa5](或十进制[19968,40869])

--数字:[0x30,0x39](或十进制[48, 57])

--小写字母:[0x61,0x7a](或十进制[97, 122])

--大写字母:[0x41,0x5a](或十进制[65, 90])

--根据编码范围来判断

--*/
--创建

create proc p_A_VIC

as

declare @count int

declare @i int

declare @text nvarchar(50)

set @i = 0

set @count = (select COUNT (*) from table  )

while(@i < @count )

begin

    set @i +=1
    --sid代表有一定循环规律的,若是无序的可以添加一个序列(Row_Number() OVER ---)。
    --select * from (SELECT *, Row_Number() OVER ( ORDER BY [sid] ) num FROM s--table ) as s where num = 3
    set @text = (select  a from table  where [sid] = @i)

    if unicode(@text) between 19968 And 40869 or unicode(@text) between 97 And 122 or unicode('a') between 65 And 90

    begin

      print 0

    end

    else

       print @text

end

--执行

exec  p_A_VIC

回答2:

select case when asciistr(a) like '%\%' then 0 else 1 end from table
其实关键的就是asciistr(),值包含\就是汉字,不包含就不是汉字

回答3:

select case when LEN(字段)<>DATALENGTH(字段) then 0 else 字段 end
FROM 表

回答4:

select case when patindex('%[吖-座]%',a)>0 then 0 else a end from table