ORA-02298 外键 定位错误的数据行


sys@TARGETAD>select * from v$version where rownum<2;

BANNER
--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

在打开外键约束的时候出现这个错误
为了找到到底是那些数据有问题:
[ora11g@targetad admin]$ pwd
/home/ora11g/product/11.2.0/rdbms/admin
[ora11g@targetad admin]$ ll|grep utlexcpt
-rw-r--r--  1 ora11g oinstall     705 Sep  3  1997 utlexcpt.sql
sys@TARGETAD>@/home/ora11g/product/11.2.0/rdbms/admin/utlexcpt.sql

ALTER TABLE lottery.table_name ENABLE VALIDATE CONSTRAINT FK_table_name3  EXCEPTIONS INTO sys.exceptions;

select * from table_name where rowid in (select row_id from exceptions);----得到有问题数据的rowid

附:日常外键的操作:
删除所有外键约束
Sql代码
select 'alter table '||table_name||' drop constraint '||constraint_name||';' from user_constraints where constraint_type='R' 
 禁用所有外键约束
Sql代码
select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R' 
启用所有外键约束
Sql代码
select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R' 

更多Oracle相关信息见Oracle 专题页面 http://www.bkjia.com/topicnews.aspx?tid=12

相关内容