处理字符串_8_判断字符串含有汉字
生活随笔
收集整理的這篇文章主要介紹了
处理字符串_8_判断字符串含有汉字
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
? ? ? ? ? ? ? ? ? ? ? ? ? ?判斷字符串含有漢字
需求描述
需求:檢索含有漢字的字符串.
解決方法:這里通過函數(shù)CHAR_LENGTH對比LENGTH進(jìn)行對比來判斷.
注: 數(shù)據(jù)庫數(shù)據(jù)集SQL腳本詳見如下鏈接地址
員工表結(jié)構(gòu)和數(shù)據(jù)初始化SQL腳本
SQL代碼
--Mysql: SELECT data,LENGTH(data) AS Len_data,CHAR_LENGTH(data) AS CharLen_Data,HEX(data) AS HexData FROM ( SELECT 'Hello,World,SQL' AS dataUNION ALL SELECT 'Data,Arithmetic' AS dataUNION ALL SELECT 'Science中國' AS dataUNION ALL SELECT '上S海H' AS data??? )A WHERE LENGTH(data)<> CHAR_LENGTH(data)執(zhí)行結(jié)果
/* 注: LENGTH() returns the length of the string measured in bytes. CHAR_LENGTH() returns the length of the string measured in characters. LENGTH:是計(jì)算字節(jié)的長度.一個(gè)漢字是算三個(gè)字符,一個(gè)數(shù)字或字母算一個(gè)字符 CHAR_LENGTH:漢字、數(shù)字、字母都算是一個(gè)字符*/-- 或者通過字符串的十六進(jìn)制并結(jié)合REGEXP來判斷. SELECT data,HEX(data) AS HexData FROM ( SELECT 'Hello,World,SQL' AS dataUNION ALL SELECT 'Data,Arithmetic' AS dataUNION ALL SELECT 'Science中國' AS dataUNION ALL SELECT '上S海H' AS data )A WHERE HEX(data) REGEXP '^(..)*(E[4-9])' --SQL Server: SELECT data FROM ( SELECT 'Hello,World,SQL' AS dataUNION ALL SELECT 'Data,Arithmetic' AS dataUNION ALL SELECT 'Science中國' AS dataUNION ALL SELECT '上S海H' AS data )A WHERE data LIKE '%[吖-座]%' --或者利用PATINDEX函數(shù)進(jìn)行判斷SELECT data FROM ( SELECT 'Hello,World,SQL' AS dataUNION ALL SELECT 'Data,Arithmetic' AS dataUNION ALL SELECT 'Science中國' AS dataUNION ALL SELECT '上S海H' AS data )A WHERE PATINDEX('%[吖-座]%',data) > 0總結(jié)
以上是生活随笔為你收集整理的处理字符串_8_判断字符串含有汉字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 镜像文件怎么用 u盘大白菜 如何用 U
- 下一篇: 电脑重启进入桌面黑屏怎么办 电脑重启后桌