我正在开发一个 MYSQL 存储过程,我需要按如下方式验证日期字段,
IF (dt_wedding_date<>'') THEN
IF (int_days_to_wedding>0) THEN
SET vc_wedding ='F';
ELSE
SET vc_wedding ='P';
END IF;
ELSE
SET vc_wedding = 'NA';
END IF;
但是当 dt_wedding_date 为 null 时,它永远不会进入 ELSE 部分。我尝试了“is null”、“is not null”、“>”、<>、trim 函数,但没有任何效果。
知道如何评估此日期字段是否为空值吗?
最佳答案
试试isnull函数,我在本地mysql上试过了
mysql> select * from data_test;
+----+------------+
| id | gmt_create |
+----+------------+
| 1 | NULL |
+----+------------+
1 row in set (0.00 sec)
mysql> select id, isnull(gmt_create) from data_test;
+----+--------------------+
| id | isnull(gmt_create) |
+----+--------------------+
| 1 | 1 |
+----+--------------------+
1 row in set (0.00 sec)
mysql>
MySQL does have an ISNULL() function. However, it works a little bit different from Microsoft's ISNULL() function.
关于mysql - 如何验证 NULL/EMPTY 的 MYSQL 日期字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12067944/