更新具有 Null 值的列

发布于 2024-09-27 06:31:32 字数 145 浏览 2 评论 0原文

我尝试按如下方式更新表:

update userloginstats set logouttime = sysdate where logouttime = null;

它没有更新具有空值的列。出了什么问题?

I tried updating a table as follows:

update userloginstats set logouttime = sysdate where logouttime = null;

It didn't update the columns with null values. What went wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

生死何惧 2024-10-04 06:31:32

将其更改为

...where logouttime is null;
                    ^^^^^^^

NULL 是一个特殊值,我们不能使用通常的 = 运算符。

来自 NULL 的 Oracle 文档

要测试空值,请使用比较条件 IS NULL 和 IS NOT NULL。如果您将任何其他条件与 null 一起使用,并且结果取决于 null 的值,则结果为 UNKNOWN,因为 null 表示缺少数据,null 不能等于或不等于任何值或到另一个空

Change it to

...where logouttime is null;
                    ^^^^^^^

NULL is a special value and we cannot use the usual = operator with it.

From the Oracle documentation for NULL:

To test for nulls, use only the comparison conditions IS NULL and IS NOT NULL. If you use any other condition with nulls and the result depends on the value of the null, then the result is UNKNOWN because null represents a lack of data, a null cannot be equal or unequal to any value or to another null

¢蛋碎的人ぎ生 2024-10-04 06:31:32

不能将 NULL 与 = 进行比较。

使用这个:

update userloginstats set logouttime= sysdate where logouttime is null;

You cannot compare NULLs with =.

Use this:

update userloginstats set logouttime= sysdate where logouttime is null;
坦然微笑 2024-10-04 06:31:32

注销时间为 null,而不是 = nullnull 永远不等于任何东西,甚至不等于它本身。因此,运算符

logouttime is null, not = null. null is never equal to anything, not even itself. Thus, the operator is.

弥枳 2024-10-04 06:31:32

您需要使用 is null 而不是 = null

update userloginstats set logouttime= sysdate where logouttime is null;

You need to use is null not = null

update userloginstats set logouttime= sysdate where logouttime is null;
梦明 2024-10-04 06:31:32

对于空值,您必须使用“IS NULL”或“IS NOT NULL”而不是 = 运算符。这是因为从技术上讲,null 既不是 true 也不是 false,而是无论哪种方式都没有值。

为了方便起见,大多数编程语言通常将 null 与 false 关联起来(从而可以使用 = 运算符),但 SQL 采用了更纯粹的方法,无论正确与否。

For nulls you must use "IS NULL" or "IS NOT NULL" rather than the = operator. This is because null is technically neither true or false, rather it's the absence of a value either way.

Most programming languages typically associate null with false for convenience (and thereby enabling the use of the = operator), but SQL takes a more purist approach, rightly or wrongly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文