Home > Database > Mysql Tutorial > mysql中如何判断当前是字符 mysql判断字段中有无汉字_MySQL

mysql中如何判断当前是字符 mysql判断字段中有无汉字_MySQL

PHP中文网
Release: 2016-05-27 14:12:04
Original
1291 people have browsed it

mysql中如何判断当前是字符 mysql判断字段中有无汉字_MySQL

使用length与char_length两个函数

length:是计算字段的长度一个汉字是算三个字符,一个数字或字母算一个字符

char_length:不管汉字还是数字或者是字母都算是一个字符

对同一字段分别使用length、char_length计算长度,并进行比较长度相同则字段中无汉字,不相同则肯定有汉字

SELECT 
  * 
FROM
  t_ad t 
WHERE t.`userid` = 974 
  AND LENGTH(
    REPLACE(REPLACE(t.`title`, '-', ''), '+', '')
  ) = 3 * CHAR_LENGTH(
    REPLACE(REPLACE(t.`title`, '-', ''), '+', '')
  ) 
  AND t.`deleteflag` = 1 ;
Copy after login

以上就是mysql中如何判断当前是字符 mysql判断字段中有无汉字_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template