Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我收到可能包含空值的数据,我想忽略它们,只插入不为空的值,例如:
INSERT INTO student (`id`, `age`, `last_value`) VALUES (1,21,3), (2,25,null), (3,23,9);
在这里,我想忽略第二行中的空值,以避免使其覆盖之前收集的最后一个值。
如果不了解您是如何构建查询的,就很难给您一个明确的答案。但是您可以检查从哪里获取值并将它们插入到查询中,如果任何值是null.
null
如果要在插入语句的上下文中处理它,则使列不为空。现在插入尝试将失败并显示特定的错误代码。您可以在客户端代码中处理它。
如果执行上下文是一次添加一行的位置,这将起作用