This article describes in detail the specific functions of MySql for judging Chinese characters, dates, and numbers. if you are interested, you can refer to several common mysql functions, the specific functions for MySql to judge Chinese characters, dates, and numbers are as follows:
1. determine whether the string is returned from Chinese characters: 1-0-non-Chinese characters
Drop function if exists fc_is_hanzi; create function fc_is_hanzi (p_str VARCHAR (1024) RETURNS int (11) not deterministic SQL security definer comment 'check whether the string is a Chinese character 'In in/* check whether the string is a Chinese character returned value: 1-Chinese 0-non-Chinese character */DECLARE _ ret, I, other_cnt, l_acode int default 0; SET _ ret = 0; SET I = 1; SET other_cnt = 0; SET l_acode = 0; WHILE I <= CHAR_LENGTH (p_str) do set l_acode = ASCII (SUBSTRING (p_str, I, 1); IF l_acode254 then set other_cnt = other_cnt + 1; end if; SET I = I + 1; END WHILE; IF other_cnt = 0 then set _ ret = 1; else set _ ret = 0; end if; RETURN _ ret; END;
2. determine whether the date format is correct (return value: 1-correct 0-error)
Drop function if exists fc_ck_date; create function fc_ck_date (p_cont CHAR (32) RETURNS tinyint (4) not deterministic SQL SECURITY DEFINER COMMENT 'determine whether the date format is correct 'begin'/* determine whether the date format is correct (return value: 1-correct 0-error) * // * the input value format is: yyyyMMdd or yyyy-MM-dd */IF (SELECT DATE_FORMAT (p_cont, '% Y % m % d') is null then return 0; else return 1; end if; END;
3. determine whether the string is a pure number (return value: 1-0-non-pure number)
Drop function if exists fc_is_num; create function fc_is_num (p_string VARCHAR (32) RETURNS int (4) not deterministic SQL SECURITY DEFINER COMMENT 'check whether the string is a pure digit 'In in/* check whether the string is a pure digit * // * return value: 1-for pure numbers 0-not pure numbers */DECLARE iResult int default 0; SELECT p_string REGEXP '^ [0-9] * $ 'into iResult; IF iResult = 1 then return 1; else return 0; end if; END;
The preceding three functions are used by MySql to determine Chinese characters, dates, and numbers. we hope they will be helpful for your learning. For more information, see PHP Chinese website (www.php1.cn )!