Home > Database > Mysql Tutorial > sql server取出内容中汉字,数字,字母

sql server取出内容中汉字,数字,字母

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:18:23
Original
1141 people have browsed it

--取出数字 IF OBJECT_ID(DBO.GET_NUMBER2) IS NOT NULL DROP FUNCTION DBO.GET_NUMBER2 GO CREATE FUNCTION DBO.GET_NUMBER2(@S VARCHAR(100)) RETURNS VARCHAR(100) AS BEGIN WHILE PATINDEX(%[^0-9]%,@S) 0 BEGIN set @s=stuff(@s,patindex(%[^0-9]%,@s),

   --取出数字

  IF OBJECT_ID(’DBO.GET_NUMBER2’) IS NOT NULL

  DROP FUNCTION DBO.GET_NUMBER2

  GO

  CREATE FUNCTION DBO.GET_NUMBER2(@S VARCHAR(100))

  RETURNS VARCHAR(100)

  AS

  BEGIN

  WHILE PATINDEX(’%[^0-9]%’,@S) > 0

  BEGIN

  set @s=stuff(@s,patindex(’%[^0-9]%’,@s),1,’’)

  END

  RETURN @S

  END

  GO

  --测试

  PRINT DBO.GET_NUMBER(’呵呵ABC123ABC’)

  GO

  --123

  --------------------------------------------------------------------

  --取出英文

  IF OBJECT_ID(’DBO.GET_STR’) IS NOT NULL

  DROP FUNCTION DBO.GET_STR

  GO

  CREATE FUNCTION DBO.GET_STR(@S VARCHAR(100))

  RETURNS VARCHAR(100)

  AS

  BEGIN

  WHILE PATINDEX(’%[^a-z]%’,@S) > 0

  BEGIN

  set @s=stuff(@s,patindex(’%[^a-z]%’,@s),1,’’)

  END

  RETURN @S

  END

  GO

  --测试

  PRINT DBO.GET_STR(’呵呵ABC123ABC’)

  GO

  --------------------------------------------------------------------

  --取出中文

  IF OBJECT_ID(’DBO.CHINA_STR’) IS NOT NULL

  DROP FUNCTION DBO.CHINA_STR

  GO

  CREATE FUNCTION DBO.CHINA_STR(@S NVARCHAR(100))

  RETURNS VARCHAR(100)

  AS

  BEGIN

  WHILE PATINDEX(’%[^吖-座]%’,@S) > 0

  SET @S = STUFF(@S,PATINDEX(’%[^吖-座]%’,@S),1,N’’)

  RETURN @S

  END

  GO

  PRINT DBO.CHINA_STR(’呵呵ABC123ABC’)

  GO

  SELECT * FROM (select ’ASDKG論壇K联通DL’ as col)TB WHERE COL LIKE N’%[吖-咗]%’

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
server
From 1970-01-01 08:00:00
0
0
0
Configure server
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template