In mysql how to determine whether the current character is mysql or not

  • 2020-06-07 05:27:36
  • OfStack

Use the length and char_length functions

length: is to calculate the length of the field. A Chinese character counts as 3 characters, and a number or letter counts as 1 character

char_length: Chinese characters, Numbers, or letters are considered one character

For the same 1 field, length and char_length are used respectively to calculate the length, and the comparison is made. If the length is the same, there will be no Chinese characters in the field; if the length is different, there must be Chinese characters


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 ;


Related articles: