0

我有一个触发器应该将空字符串转换nulltinyint(1)布尔列:

CREATE TRIGGER convertToNull
BEFORE INSERT ON MyTable
FOR EACH ROW
SET new.myBoolean = nullif(new.myBoolean, '');

问题是,它也转换0null.

我检查了:

mysql> select nullif(0, '');
+---------------+
| nullif(0, '') |
+---------------+
|          NULL |
+---------------+
1 row in set (0.00 sec)

如何nullif更严格,这样只有空字符串才会被转换为null

4

0 回答 0