您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

使用自定义函数验证 MySQL 中的日期

2024/11/5 11:58:30发布29次查看
让我们创建一个自定义函数来验证 mysql 中的日期 -
mysql> set global log_bin_trust_function_creators=1;query ok, 0 rows affected (0.03 sec)mysql> delimiter //mysql> create function isvaliddate(actualdate varchar(255)) returns int -> begin -> declare flag int; -> if (select length(date(actualdate)) is not null ) then -> set flag = 1; -> else -> set flag = 0; -> end if; -> return flag; -> end -> //query ok, 0 rows affected (0.11 sec)mysql> delimiter ;
案例1 −
当参数为null值时,即要检查的日期不是实际日期。使用select语句调用函数 −
mysql> select isvaliddate(null);
这将产生以下输出,即不是日期 -
+-------------------+| isvaliddate(null) |+-------------------+| 0 |+-------------------+1 row in set (0.05 sec)
情况 2 -
当参数是实际日期值时。使用 select 语句调用函数 -
mysql> select isvaliddate('2019-10-21');
这将产生以下输出,即 1,实际日期 -
+---------------------------+| isvaliddate('2019-10-21') |+---------------------------+| 1 |+---------------------------+1 row in set (0.00 sec)
以上就是使用自定义函数验证 mysql 中的日期的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product