DELETE from dbo.T_LIAV_AGENT_STATE_APPROVAL SAP
WHERE EXISTS (SELECT UNIQUE 1 FROM MCS_SYNC_STATE_APPR APP
inner join MCS_SYNC_NAME SN on SN.SE_NAME_ID = APP.SE_NAME_ID
and SN.ACTION in('U','S')
Where APP.SE_name_id = SAP.AV_NAME_ID
and APP.SYNC_INSTANCE_ID = param_inst_ID);
COMMIT;
INSERT INTO dbo.T_LIAV_AGENT_STATE_APPROVAL
SELECT UNIQUE
APP.SE_NAME_ID AS AV_NAME_ID,
APP.STATE AS AV_STATE,
APP.APPROVAL_TYPE AS AV_APPROVAL_TYPE,
APP.START_DATE AS AV_START_DATE,
APP.END_DATE AS AV_END_DATE,
APP.APPOINTED AS AV_APPOINTED,
APP.RENEWAL_DATE AS AV_RENEWAL_DATE,
APP.LICENSE AS AV_LICENSE,
COMPANY_NAME_ID as AV_COMPANY_CODE,
SYSDATE AS TSTAMP,
SYNC_USER_NAME_ID AS AV_FIRST_USER_ID,
SYSDATE AS AV_FIRST_DATE,
NULL AS AV_LAST_USER_ID,
NULL AS AV_LAST_DATE
FROM MCS_SYNC_STATE_APPR APP
WHERE exists (select 1 from t_liag_agent AG
where AG.ag_name_id = APP.SE_NAME_ID)
and APP.SYNC_INSTANCE_ID = param_inst_ID;
这是SQL部分,我在调试代码时遇到错误:
ORA-00001:违反了唯一约束主键T_LIAV_AGENT_STATE_APPROVAL ...
这些是主键约束依赖于AV_NAME_ID, AV_STATE
..
根据我的说法没有重复的数据...你认为还有其他原因吗?
答案 0 :(得分:5)
如果你有'创建表'特权,使用dbms_errlog包。
运行脚本:
begin
dbms_errlog.create_error_log('DBO.T_LIAV_AGENT_STATE_APPROVAL');
end;
/
使用附加子句运行INSERT脚本:
INSERT INTO dbo.T_LIAV_AGENT_STATE_APPROVAL
SELECT ...
FROM ...
LOG ERRORS INTO err$_T_LIAV_AGENT_STATE_APPROVAL REJECT LIMIT UNLIMITED;
检查错误记录表中的错误:
select * from err$_T_LIAV_AGENT_STATE_APPROVAL;
您将看到所有违反约束的记录和错误消息。
答案 1 :(得分:0)
与Insert表语句相比,Select语句缺少一列,因此出现此错误。当我将该列添加到select语句时,它完美地运行了。
答案 2 :(得分:0)
如果您不确定违反了哪个唯一约束,则可以运行以下SQL:
Select Distinct table_name
From all_indexes
Where index_name = 'CONSTRAINT_NAME';