In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "SQL Server extracting numbers, English and Chinese sql sentences". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "SQL Server extracting numbers, English and Chinese sql sentences".
-- SQL determines whether the field value has a Chinese create function fun_getCN (@ str nvarchar (4000)) returns nvarchar (4000) as begin declare @ word nchar (1), @ CN nvarchar (4000) set @ CN='' while len (@ str) > 0 begin set @ word=left (@ str,1) if unicode (@ word) between 19968 and 19968 set @ CN=@CN+@word set @ str=right (@ str) Len (@ str)-1) end return @ CN end select dbo.fun_getCN ('ASDKG Forum KDL')-- Forum select dbo.fun_getCN (' ASDKG Forum KDL')-- Forum select dbo.fun_getCN ('ASDKDL')-empty-extract digital IF OBJECT_ID (' DBO.GET_NUMBER2) ') IS NOT NULLDROP FUNCTION DBO.GET_NUMBER2GOCREATE FUNCTION DBO.GET_NUMBER2 (@ S VARCHAR) RETURNS VARCHAR (100) ASBEGINWHILE PATINDEX ('% [^ 0-9]%' @ S) > 0BEGINset @ s=stuff ('% [^ 0-9]%', @ s), 1 '') ENDRETURN @ SENDGO-- Test PRINT DBO.GET_NUMBER ('hehe ABC123ABC') GO--123---- extract English IF OBJECT_ID (' DBO.GET_STR') IS NOT NULLDROP FUNCTION DBO. GET_STRGOCREATE FUNCTION DBO.GET_STR (@ S VARCHAR) RETURNS VARCHAR (100) ASBEGINWHILE PATINDEX ('% [^ amurz]%' @ S) > 0BEGINset @ s=stuff (@ sdepartment patindex ('% [^ a murz]%', @ s), 1 '') ENDRETURN @ SENDGO-- Test PRINT DBO.GET_STR ('hehe ABC123ABC') GO---- extract Chinese IF OBJECT_ID (' DBO.CHINA_STR') IS NOT NULLDROP FUNCTION DBO.CHINA_STRGOCREATE FUNCTION DBO.CHINA_STR (@ S NVARCHAR) RETURNS VARCHAR (100) ASBEGINWHILE PATINDEX ('% [^ A-seat]%' @ S) > 0SET @ S = STUFF (@ S Magee Patten ('% [^ A-seat]%', @ S), 1 Nasty') RETURN @ SENDGOPRINT DBO.CHINA_STR ('hehe ABC123ABC') GO---- filter repeating characters IF OBJECT_ID (' DBO.DISTINCT_STR') IS NOT NULLDROP FUNCTION DBO.DISTINCT_STRGOCREATE FUNCTION DBO.DISTINCT_STR (@ S NVARCHAR) @ SPLIT VARCHAR (50)) RETURNS VARCHAR (100) ASBEGINIF @ S IS NULL RETURN (NULL) DECLARE @ NEW VARCHAR (50), @ INDEX INT,@TEMP VARCHAR (50) IF LEFT (@ SMagne1) @ SPLITSET @ S = @ SPLIT+@SIF RIGHT (@ SMague 1) @ SPLITSET @ S = @ S+@SPLITWHILE CHARINDEX (@ SPLIT,@S) > 0 AND LEN (@ S) 1BEGINSET @ INDEX = CHARINDEX (@ SPLIT,@S) SET @ TEMP = LEFT (@ Stemiere (@ SPLIT,@S) @ INDEX+LEN (@ SPLIT)) IF @ NEW ISNULL SET @ NEW = ISNULL (@ NEW,'') + @ TEMPELSESET @ NEW = ISNULL (@ NEW,'') + REPLACE (@ TEMP,@SPLIT,'') + @ SPLITWHILE CHARINDEX (@ TEMP,@S) > 0BEGINSET @ S=STUFF (@ TEMP,@S) + LEN (@ SPLIT), CHARINDEX (@ SPLIT,@S,CHARINDEX (@ TEMP,@S) + LEN (@ SPLIT))-CHARINDEX (@ TEMP,@S),') ENDENDRETURN RIGHT (LEFT (@ NEW) LEN (@ NEW)-1), LEN (LEFT (@ NEW,LEN (@ NEW)-1)-1) ENDGOPRINT DBO.DISTINCT_STR CGO---- filters repeating characters 2IF OBJECT_ID ('DBO.DISTINCT_STR2') IS NOT NULLDROP FUNCTION DBO.DISTINCT_STR2GOCREATE FUNCTION DBO.DISTINCT_STR2 (@ S varchar (8000)) RETURNS VARCHAR (100) ASBEGINIF @ S IS NULL RETURN (NULL) DECLARE @ NEW VARCHAR (50) @ INDEX INT,@TEMP VARCHAR (50) WHILE LEN (@ S) > 0BEGINSET @ NEW=ISNULL (@ NEW,'') + LEFT (@ SMagne1) SET @ S=REPLACE (@ SMagol left (@ SMagne1) '') ENDRETURN @ NEWENDGOSELECT DBO.DISTINCT_STR2 ('AABCCD')-ABCDGO----IF OBJECT_ID (' DBO.SPLIT_STR') IS NOT NULLDROP FUNCTION DBO.SPLIT_STRGOCREATE FUNCTION DBO.SPLIT_STR (@ S varchar (8000) -- string @ INDEX int containing multiple data items,-- location of the data item to be obtained @ SPLIT varchar (10)-- data separator) RETURNS VARCHAR (100) ASBEGINIF @ S IS NULL RETURN (NULL) DECLARE @ SPLITLEN intSELECT @ SPLITLEN=LEN (@ SPLIT+'A')-2WHILE @ INDEX > 1 AND CHARINDEX (@ SPLIT,@S+@SPLIT) > 0SELECT @ INDEX=@INDEX-1,@S=STUFF (@ SPLIT,@S+@SPLIT) + @ SPLITLEN '') RETURN (ISNULL (LEFT (@ SMagneCHARINDEX (@ SPLIT,@S+@SPLIT)-1),') ENDGOPRINT DBO.SPLIT_STR ('AA | BB | CC',2,' |')-- GO Thank you for your reading The above is the content of "SQL Server extracting numbers, English and Chinese sql sentences". After the study of this article, I believe you have a deeper understanding of the problem of SQL Server extracting numbers, English and Chinese sql sentences, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.