This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15603|Reply: 0

[Source] SQL Server fields can only contain Chinese characters, letters, and numbers

[Copy link]
Posted on 12/7/2018 1:24:31 PM | | | |
Because you need to query some data in the database, the field content can only contain Chinese characters, letters, and numbers, and cannot contain special symbols (except for special data)
Let's take a look at the effects first, as follows:




Resources:

How database sql queries a field with only numbers and letters or Chinese characters

- Contains only numbers and letters

select column name from table name where REGEXP_LIKE(column name,'^([\u4e00-\u9fa5]+)$')

--Only contains Chinese characters

select column name from table name where length(column name)=length(ASCIISTR(column name))-length(replace(ASCIISTR(column name),'\',''))


Note: The asciistr() function will convert the string into an ASCII value, and if the character is in the ASCII code table, it will be converted into the corresponding character of ASCII; If there are none, such as Chinese and full-width characters, it will be converted to \xxxx format.


The length() function counts that the Chinese length is 1, and the Chinese character corresponding to lengthb() is 2 bytes. The above statement is to compare the number of Chinese characters with the number of \ after converting to ASCII values, if they are equal, it means that they are all Chinese characters. (If you want to exclude the influence of full-width symbols, you need to first change the field to half width, and the function is to_single_byte()).



sqlserver2008r2 looks for the first position where non-Chinese alphanumeric numbers appear

Environment:
The test database sqlserver2008r2 has a sorting method of Chinese_PRC_CI_AS, and I have not tried it in other environments
Statement


Return value: 4

My solution

(End)





Previous:Prize questionnaire, how did you know about this site?
Next:Modify to your own gateway, and the internal and external networks are on at the same time provided that there are two network cards
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com