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