MySql determines the specific functions of Chinese characters, dates, and numbers, and mysql Chinese Characters

Source: Internet
Author: User
Tags mysql functions

MySql determines the specific functions of Chinese characters, dates, and numbers, and mysql Chinese Characters

Several mysql functions are commonly used. 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_acode <124 or l_acode> 254 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. They hope to help you learn them.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.