暂无图片
oracle 主键唯一索引,约束一直生效的,索引状态为有效。但有重复值。什么原因呢?
我来答
分享
马老师r
2020-12-03
oracle 主键唯一索引,约束一直生效的,索引状态为有效。但有重复值。什么原因呢?
暂无图片 5M

oracle 主键唯一索引,约束一直生效的,索引状态为有效。但有重复值。什么原因呢?

dba_indexes的STATUS是VALID
dba_constraints VALIDATED VALIDATED

我来答
添加附件
收藏
分享
问题补充
5条回答
默认
最新
JiekeXu
暂无图片

按理来说主键唯一性,没有重复值,不应该出现这样的情况的,你的重复值是什么样的?会不会是由于插入值时带入的空格或者引号问题呢,请仔细检查一下。

暂无图片 评论
暂无图片 有用 0
姜殿斌

“主键唯一性,没有重复值“,你说的对。贴出具体细节和实验过程分析。

暂无图片 评论
暂无图片 有用 0
马老师r

案例1.png2.png3.png

暂无图片 评论
暂无图片 有用 0
肖杰

这个情况应该就是创建主键的时候加了novalidate参数,很容易模拟:

SQL> insert into test_index select * from test_index;

72940 rows created.

SQL> commit;

Commit complete.

SQL> alter table test_index add constraints pk_objname primary key (object_Name) novalidate;

Table altered.

SQL> select object_Name,count(*) from test_index group by object_Name having count(1) > 1 fetch first 10 rows only;

OBJECT_NAME            COUNT(*)
-------------------- ----------
C_COBJ#                       2
I_COLTYPE2                    2
SUBCOLTYPE$                   2
I_NTAB2                       2
I_NTAB3                       2
I_REFCON2                     2
EV$                           2
PDB_ALERT_SEQUENCE            2
IMORDERBY$                    2
SYS_IL0000000326C000          2
03$$

SQL> select CONSTRAINT_NAME,TABLE_NAME,CONSTRAINT_TYPE,STATUS from dba_constraints where table_name ='TEST_INDEX';

CONSTRAINT_NAME TABLE_NAME      C STATUS
--------------- --------------- - --------
PK_OBJNAME      TEST_INDEX      P ENABLED

暂无图片 评论
暂无图片 有用 0
马老师r

SYS@orcl1>create table test_index as select * from dba_tables where rowNum<30;

Table created.

SYS@orcl1>insert into test_index select * from dba_tables where rowNum<28;

27 rows created.

SYS@orcl1>commit;

Commit complete.

SYS@orcl1> select TABLE_NAME ,count() from test_index group by TABLE_NAME having count(1) > 1 fetch first 10 rows only;
select TABLE_NAME ,count(
) from test_index group by TABLE_NAME having count(1) > 1 fetch first 10 rows only
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SYS@orcl1>select TABLE_NAME ,count(*) from test_index group by TABLE_NAME having count(1) > 1 ;

TABLE_NAME COUNT(*)


ICOL$ 2
TS$ 2
UNDO$ 2
FET$ 2
OBJ$ 2
USER$ 2
UET$ 2
SEG$ 2
CLU$ 2
IND$ 2
COL$ 2

TABLE_NAME COUNT(*)


PROXY_DATA$ 2
LOB$ 2
FILE$ 2
TSQ$ 2
COLTYPE$ 2

16 rows selected.

SYS@orcl1> alter table test_index add constraints pk_objname1 primary key (TABLE_NAME) novalidate;
alter table test_index add constraints pk_objname1 primary key (TABLE_NAME) novalidate
*
ERROR at line 1:
ORA-02437: cannot validate (SYS.PK_OBJNAME1) - primary key violated

SYS@orcl1>
执行不成功。报错的呀~

暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏