有两个表x_ass_table
和i_ass_table
:
我正在将包含 13000 条记录的 x_ass_table
数据插入到 i_ass_table:
i_ass_table
中有一个唯一约束
CREATE UNIQUE INDEX i_ass_table_pk ON i_ass_table(ASSIGNMENT_NUMBER,EFFECTIVE_START_DATE,EFFECTIVE_END_DATE,EFFECTIVE_LATEST_CHANGE)
insert into i_ass_table select * from x_ass_table;
我收到唯一约束错误
00001. 00000 - "unique constraint (%s.%s) violated"
*Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
For Trusted Oracle configured in DBMS MAC mode, you may see
this message if a duplicate entry exists at a different level.
*Action: Either remove the unique restriction or do not insert the key.
这一定是数据错误。但是我如何检查 13000 条记录中哪些数据损坏或重复
最佳答案
您可以使用 count()
函数的分析版本,通过您想要唯一的字段组合对源行进行编号,然后查询以查看哪个组合具有多个行。例如:
SELECT *
FROM (SELECT *,
COUNT() OVER (PARTITION BY assignment_number,
effective_start_date,
effective_end_date,
effective_latest_change) AS c
FROM x_ass_table) t
WHERE c > 1
关于sql - 在 SQL 中插入时出现唯一键约束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34782855/