Determines whether the string is a valid value or a date.

Source: Internet
Author: User


Determines whether the string is a valid value or a date.


SQL Server built-in functions

Isnumeric ():

Isdate ()


MySQL does not have built-in functions and requires human-written functions.

Valid value:


Drop function if exists fc_ck_date;


Delimiter $


Create Function fc_ck_date (

P_cont char (32)

)

Returns tinyint (4)

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


$ Delimiter;


-- Determines whether the string is a valid date.


Drop function if exists fc_is_num;


Create Function fc_is_num (

P_string varchar (32)

)

Returns int (4)

Comment 'check whether the string is a pure number'

Begin

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;


Reference link:

Http://www.veryhuo.com/a/view/11905.html



This article is from the sqlserver MySQL blog, please be sure to keep this source http://dwchaoyue.blog.51cto.com/2826417/1533922

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.