如何在 NOT NULL 字段中存储 NULL?

发布于 2024-08-11 00:02:42 字数 206 浏览 3 评论 0原文

我刚刚在我们的测试数据库中的 NOT-NULL 字段中发现了 NULL 值。他们怎么能到那里呢?我知道可以使用 NOVALIDATE 子句更改 NOT-NULL 约束,但这会更改 USER_OBJECTS 中表的last_ddl_time。该时间小于这些记录的创建日期。还有什么我忽略的吗?或者这肯定是某人的手工工作?

如果相关的话,表已分区并按索引组织。 Oracle版本是9.2

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table's last_ddl_time in USER_OBJECTS. And that time is less than the date that those records were created. Is there something else I'm overlooking? Or is that someone's manual work for sure?

Table is partitioned and index-organized if that is relevant.
Oracle version is 9.2

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

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

发布评论

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

评论(3

你另情深 2024-08-18 00:02:42

NOT NULL 列条件与其他约束不同:您可以禁用 NOT NULL 约束,但如果您使用 NOVALIDATE 重新启用该约束,则该列不会被视为 NOT NULL。让我们构建一个小示例:

SQL> CREATE TABLE tt (ID NUMBER NOT NULL);

Table created

SQL> SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'TT';

COLUMN_NAME                    NULLABLE
------------------------------ --------
ID                             N

现在,如果我禁用约束并使用 NOVALIDATE 重新启用它,Oracle 将不会将该列视为 NOT NULLABLE:

SQL> SELECT constraint_name, search_condition
  2    FROM user_constraints WHERE table_name = 'TT';

CONSTRAINT_NAME                SEARCH_CONDITION
------------------------------ ----------------------------
SYS_C00786538                  "ID" IS NOT NULL

SQL> ALTER TABLE tt MODIFY CONSTRAINT SYS_C00786538 DISABLE;

Table altered

SQL> ALTER TABLE tt MODIFY CONSTRAINT SYS_C00786538 ENABLE NOVALIDATE;

Table altered

SQL> SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'TT';

COLUMN_NAME                    NULLABLE
------------------------------ --------
ID                             Y

所以,我会说,如果 NOT NULLABLE 列中有 NULL 值(根据我的最后一个查询)您有一个错误(联系支持人员?)

The NOT NULL column condition is not like other constraints: you can disable a NOT NULL constraint but the column won't be considered NOT NULL if you reenable the constraint with NOVALIDATE. Let's build a small example:

SQL> CREATE TABLE tt (ID NUMBER NOT NULL);

Table created

SQL> SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'TT';

COLUMN_NAME                    NULLABLE
------------------------------ --------
ID                             N

now if I disable the constraint and reenable it with NOVALIDATE, the column won't be considered NOT NULLABLE by Oracle:

SQL> SELECT constraint_name, search_condition
  2    FROM user_constraints WHERE table_name = 'TT';

CONSTRAINT_NAME                SEARCH_CONDITION
------------------------------ ----------------------------
SYS_C00786538                  "ID" IS NOT NULL

SQL> ALTER TABLE tt MODIFY CONSTRAINT SYS_C00786538 DISABLE;

Table altered

SQL> ALTER TABLE tt MODIFY CONSTRAINT SYS_C00786538 ENABLE NOVALIDATE;

Table altered

SQL> SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'TT';

COLUMN_NAME                    NULLABLE
------------------------------ --------
ID                             Y

So, I would say that if you have NULL values in a NOT NULLABLE column (as per my last query) you have a bug (contact support?)

记忆消瘦 2024-08-18 00:02:42

检查约束是否已暂停/禁用

Check If the constraint are suspended / Disabled

念﹏祤嫣 2024-08-18 00:02:42

您确定这些列确实为空吗?换句话说:

SELECT field
  FROM your_table
 WHERE not_null_field IS NULL;

返回行?也许他们刚刚得到了不可显示的数据......

And you're sure these columns are really null? In other words:

SELECT field
  FROM your_table
 WHERE not_null_field IS NULL;

returns rows? Perhaps they've just got non-displayable data...

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