从 Coldfusion 向 MySQL 插入 NULL 值
我有一个数据库,其中一个字段可能有值。根据情况可能需要删除初始值并将其替换为 NULL。
如何在空字段中插入 NULL 值?
欣赏它。
I have a database that may have a value in one of the fields. Circumstance may need to remove the initial value and replace it with a NULL.
How can NULL values be inserted in an empty field?
Appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将编写一个如下所示的查询:
此外,空白字符串和 NULL 值之间存在差异。关于 NULL 需要记住的一点是,它不等于除 NULL 之外的任何东西。但它也不等于非 NULL 值。因此,如果表中有 3 条记录:
当您运行此查询时:
您将仅获得记录 3。确保记录 2 包含在结果集中的方法是更改您的查询,如下所示:
合并的目的是检查第一个参数为 NULL,如果第一个参数为 NULL,则使用第二个参数的值。在上面的示例中,我将“16”作为第二个参数,但您可以使用任何您想要的值,只要它与您要比较的值不同(在本例中为 15)。
You'd write a query that's something like this:
Also, there's a difference between a blank string and a NULL value. The thing to remember about NULL is that it doesn't equate to anything but NULL. But it also doesn't equate to non-NULL values. So if you have three records in your table:
When you run this query:
you will ONLY get record 3. The way to make sure record 2 is included in the resultset is to alter your query as such:
The purpose of coalesce is to check the first parameter for NULL-ness, and use the value of the second parameter instead if the first parameter is NULL. In the above example, I've put '16' as the second parameter, but you can use any value you want as long as it's not the same as what you're comparing for (in this case, 15).