Get the information about source row causing “ORA-00001 unique constraint violated” error in Oracle
Is there any way to get the complete row or selected columns of source row/table which is causing
"ORA-00001 unique constraint violated" error.
Here is a small example.
create table DW_DATA (
file_id number,
process_date date,
record_info varchar2(50),
constraint uk_pd_ri unique (process_date,
record_info)
);
After create, Inserting first record,
insert into DW_DATA
values (100,
'10-Jul-2018',
'Information about row');
commit;
Now, I am inserting a new row.
insert into DW_DATA
values (200,
'10-Jul-2018',
'Information about row');
It will throw an error "ORA-00001 unique constraint violated".
So, my question is, is it possible to get the file_id of source row i.e. 100 using DBMS_ERRLOG concept. Or is there any other approach available to get the info about source row.
sql oracle plsql
add a comment |
Is there any way to get the complete row or selected columns of source row/table which is causing
"ORA-00001 unique constraint violated" error.
Here is a small example.
create table DW_DATA (
file_id number,
process_date date,
record_info varchar2(50),
constraint uk_pd_ri unique (process_date,
record_info)
);
After create, Inserting first record,
insert into DW_DATA
values (100,
'10-Jul-2018',
'Information about row');
commit;
Now, I am inserting a new row.
insert into DW_DATA
values (200,
'10-Jul-2018',
'Information about row');
It will throw an error "ORA-00001 unique constraint violated".
So, my question is, is it possible to get the file_id of source row i.e. 100 using DBMS_ERRLOG concept. Or is there any other approach available to get the info about source row.
sql oracle plsql
1
You can useinsert into ... log errors into ...
but that would not cause the insert to fail!
– a_horse_with_no_name
Nov 12 '18 at 11:46
log errors will give me the information about new row i.e. row having file_id 200 if I create the ERR$ table using DBMS_ERRLOG package.
– Sanket
Nov 12 '18 at 11:49
Performance would take a hit, but you could use a merge, join the input to the source table, then use a when matched / not matched to divide the 2 scenarios up, while having access to both records.
– Andrew
Nov 12 '18 at 11:50
add a comment |
Is there any way to get the complete row or selected columns of source row/table which is causing
"ORA-00001 unique constraint violated" error.
Here is a small example.
create table DW_DATA (
file_id number,
process_date date,
record_info varchar2(50),
constraint uk_pd_ri unique (process_date,
record_info)
);
After create, Inserting first record,
insert into DW_DATA
values (100,
'10-Jul-2018',
'Information about row');
commit;
Now, I am inserting a new row.
insert into DW_DATA
values (200,
'10-Jul-2018',
'Information about row');
It will throw an error "ORA-00001 unique constraint violated".
So, my question is, is it possible to get the file_id of source row i.e. 100 using DBMS_ERRLOG concept. Or is there any other approach available to get the info about source row.
sql oracle plsql
Is there any way to get the complete row or selected columns of source row/table which is causing
"ORA-00001 unique constraint violated" error.
Here is a small example.
create table DW_DATA (
file_id number,
process_date date,
record_info varchar2(50),
constraint uk_pd_ri unique (process_date,
record_info)
);
After create, Inserting first record,
insert into DW_DATA
values (100,
'10-Jul-2018',
'Information about row');
commit;
Now, I am inserting a new row.
insert into DW_DATA
values (200,
'10-Jul-2018',
'Information about row');
It will throw an error "ORA-00001 unique constraint violated".
So, my question is, is it possible to get the file_id of source row i.e. 100 using DBMS_ERRLOG concept. Or is there any other approach available to get the info about source row.
sql oracle plsql
sql oracle plsql
edited Nov 12 '18 at 13:08
Shaili
618826
618826
asked Nov 12 '18 at 11:40
SanketSanket
111
111
1
You can useinsert into ... log errors into ...
but that would not cause the insert to fail!
– a_horse_with_no_name
Nov 12 '18 at 11:46
log errors will give me the information about new row i.e. row having file_id 200 if I create the ERR$ table using DBMS_ERRLOG package.
– Sanket
Nov 12 '18 at 11:49
Performance would take a hit, but you could use a merge, join the input to the source table, then use a when matched / not matched to divide the 2 scenarios up, while having access to both records.
– Andrew
Nov 12 '18 at 11:50
add a comment |
1
You can useinsert into ... log errors into ...
but that would not cause the insert to fail!
– a_horse_with_no_name
Nov 12 '18 at 11:46
log errors will give me the information about new row i.e. row having file_id 200 if I create the ERR$ table using DBMS_ERRLOG package.
– Sanket
Nov 12 '18 at 11:49
Performance would take a hit, but you could use a merge, join the input to the source table, then use a when matched / not matched to divide the 2 scenarios up, while having access to both records.
– Andrew
Nov 12 '18 at 11:50
1
1
You can use
insert into ... log errors into ...
but that would not cause the insert to fail!– a_horse_with_no_name
Nov 12 '18 at 11:46
You can use
insert into ... log errors into ...
but that would not cause the insert to fail!– a_horse_with_no_name
Nov 12 '18 at 11:46
log errors will give me the information about new row i.e. row having file_id 200 if I create the ERR$ table using DBMS_ERRLOG package.
– Sanket
Nov 12 '18 at 11:49
log errors will give me the information about new row i.e. row having file_id 200 if I create the ERR$ table using DBMS_ERRLOG package.
– Sanket
Nov 12 '18 at 11:49
Performance would take a hit, but you could use a merge, join the input to the source table, then use a when matched / not matched to divide the 2 scenarios up, while having access to both records.
– Andrew
Nov 12 '18 at 11:50
Performance would take a hit, but you could use a merge, join the input to the source table, then use a when matched / not matched to divide the 2 scenarios up, while having access to both records.
– Andrew
Nov 12 '18 at 11:50
add a comment |
3 Answers
3
active
oldest
votes
When I run the query, I get:
ORA-00001: unique constraint (FIDDLE_RSGKXYATHHTELGHIJXGD.UK_PD_RI) violated
This contains the unique constraint name -- "UK_PD_RI".
You can then look up the data based on the columns used for the constraint:
select *
from dw_data
where process_date = '10-Jul-2018' and record_info = 'Information about row';
Admittedly, this is not a single step process. You can do something more directly using error logging. That is a little more involved. Here is a good place to read about it. However, I don't think error logging will provide the rowid of the existing row for a unique constraint violation.
I was looking for single step process as I want to update FILE_IDs of existing rows for the records which are rejected because of ORA-00001. And the DW_DATA is huge table having billions of rows, so the lookup could cause performance issues.
– Sanket
Nov 12 '18 at 12:08
add a comment |
select process_date, record_info, count(*) from DW_DATA
group by process_date, record_info
having count(*) >1
you will have the list of UK values which are duplicating.
1
That will never return anything
– a_horse_with_no_name
Nov 12 '18 at 12:26
add a comment |
You just need to use MERGE statement:
MERGE INTO DW_DATA t1
USING (
select 200 as file_id,
'10-Jul-2018' as process_date,
'Information about row' as record_info from dual
) t2
ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info)
WHEN MATCHED THEN UPDATE SET file_id = t2.file_id
WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info);
Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command.
MERGE INTO DW_DATA t1 USING (select 200 as file_id,'10-Jul-2018' as process_date, 'Information about row' as record_info from dual )t2 ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info) WHEN MATCHED THEN UPDATE SET file_id = t2.file_id WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info) ; Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command;
– evgeniya makarova
Nov 13 '18 at 14:21
do you mean select's result?
– evgeniya makarova
Nov 13 '18 at 14:38
The edits have improved this answer.
– KevinO
Nov 13 '18 at 14:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261396%2fget-the-information-about-source-row-causing-ora-00001-unique-constraint-violat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
When I run the query, I get:
ORA-00001: unique constraint (FIDDLE_RSGKXYATHHTELGHIJXGD.UK_PD_RI) violated
This contains the unique constraint name -- "UK_PD_RI".
You can then look up the data based on the columns used for the constraint:
select *
from dw_data
where process_date = '10-Jul-2018' and record_info = 'Information about row';
Admittedly, this is not a single step process. You can do something more directly using error logging. That is a little more involved. Here is a good place to read about it. However, I don't think error logging will provide the rowid of the existing row for a unique constraint violation.
I was looking for single step process as I want to update FILE_IDs of existing rows for the records which are rejected because of ORA-00001. And the DW_DATA is huge table having billions of rows, so the lookup could cause performance issues.
– Sanket
Nov 12 '18 at 12:08
add a comment |
When I run the query, I get:
ORA-00001: unique constraint (FIDDLE_RSGKXYATHHTELGHIJXGD.UK_PD_RI) violated
This contains the unique constraint name -- "UK_PD_RI".
You can then look up the data based on the columns used for the constraint:
select *
from dw_data
where process_date = '10-Jul-2018' and record_info = 'Information about row';
Admittedly, this is not a single step process. You can do something more directly using error logging. That is a little more involved. Here is a good place to read about it. However, I don't think error logging will provide the rowid of the existing row for a unique constraint violation.
I was looking for single step process as I want to update FILE_IDs of existing rows for the records which are rejected because of ORA-00001. And the DW_DATA is huge table having billions of rows, so the lookup could cause performance issues.
– Sanket
Nov 12 '18 at 12:08
add a comment |
When I run the query, I get:
ORA-00001: unique constraint (FIDDLE_RSGKXYATHHTELGHIJXGD.UK_PD_RI) violated
This contains the unique constraint name -- "UK_PD_RI".
You can then look up the data based on the columns used for the constraint:
select *
from dw_data
where process_date = '10-Jul-2018' and record_info = 'Information about row';
Admittedly, this is not a single step process. You can do something more directly using error logging. That is a little more involved. Here is a good place to read about it. However, I don't think error logging will provide the rowid of the existing row for a unique constraint violation.
When I run the query, I get:
ORA-00001: unique constraint (FIDDLE_RSGKXYATHHTELGHIJXGD.UK_PD_RI) violated
This contains the unique constraint name -- "UK_PD_RI".
You can then look up the data based on the columns used for the constraint:
select *
from dw_data
where process_date = '10-Jul-2018' and record_info = 'Information about row';
Admittedly, this is not a single step process. You can do something more directly using error logging. That is a little more involved. Here is a good place to read about it. However, I don't think error logging will provide the rowid of the existing row for a unique constraint violation.
answered Nov 12 '18 at 11:49
Gordon LinoffGordon Linoff
763k35296400
763k35296400
I was looking for single step process as I want to update FILE_IDs of existing rows for the records which are rejected because of ORA-00001. And the DW_DATA is huge table having billions of rows, so the lookup could cause performance issues.
– Sanket
Nov 12 '18 at 12:08
add a comment |
I was looking for single step process as I want to update FILE_IDs of existing rows for the records which are rejected because of ORA-00001. And the DW_DATA is huge table having billions of rows, so the lookup could cause performance issues.
– Sanket
Nov 12 '18 at 12:08
I was looking for single step process as I want to update FILE_IDs of existing rows for the records which are rejected because of ORA-00001. And the DW_DATA is huge table having billions of rows, so the lookup could cause performance issues.
– Sanket
Nov 12 '18 at 12:08
I was looking for single step process as I want to update FILE_IDs of existing rows for the records which are rejected because of ORA-00001. And the DW_DATA is huge table having billions of rows, so the lookup could cause performance issues.
– Sanket
Nov 12 '18 at 12:08
add a comment |
select process_date, record_info, count(*) from DW_DATA
group by process_date, record_info
having count(*) >1
you will have the list of UK values which are duplicating.
1
That will never return anything
– a_horse_with_no_name
Nov 12 '18 at 12:26
add a comment |
select process_date, record_info, count(*) from DW_DATA
group by process_date, record_info
having count(*) >1
you will have the list of UK values which are duplicating.
1
That will never return anything
– a_horse_with_no_name
Nov 12 '18 at 12:26
add a comment |
select process_date, record_info, count(*) from DW_DATA
group by process_date, record_info
having count(*) >1
you will have the list of UK values which are duplicating.
select process_date, record_info, count(*) from DW_DATA
group by process_date, record_info
having count(*) >1
you will have the list of UK values which are duplicating.
edited Nov 12 '18 at 12:26
a_horse_with_no_name
293k46448541
293k46448541
answered Nov 12 '18 at 11:53
evgeniya makarovaevgeniya makarova
11
11
1
That will never return anything
– a_horse_with_no_name
Nov 12 '18 at 12:26
add a comment |
1
That will never return anything
– a_horse_with_no_name
Nov 12 '18 at 12:26
1
1
That will never return anything
– a_horse_with_no_name
Nov 12 '18 at 12:26
That will never return anything
– a_horse_with_no_name
Nov 12 '18 at 12:26
add a comment |
You just need to use MERGE statement:
MERGE INTO DW_DATA t1
USING (
select 200 as file_id,
'10-Jul-2018' as process_date,
'Information about row' as record_info from dual
) t2
ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info)
WHEN MATCHED THEN UPDATE SET file_id = t2.file_id
WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info);
Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command.
MERGE INTO DW_DATA t1 USING (select 200 as file_id,'10-Jul-2018' as process_date, 'Information about row' as record_info from dual )t2 ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info) WHEN MATCHED THEN UPDATE SET file_id = t2.file_id WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info) ; Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command;
– evgeniya makarova
Nov 13 '18 at 14:21
do you mean select's result?
– evgeniya makarova
Nov 13 '18 at 14:38
The edits have improved this answer.
– KevinO
Nov 13 '18 at 14:50
add a comment |
You just need to use MERGE statement:
MERGE INTO DW_DATA t1
USING (
select 200 as file_id,
'10-Jul-2018' as process_date,
'Information about row' as record_info from dual
) t2
ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info)
WHEN MATCHED THEN UPDATE SET file_id = t2.file_id
WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info);
Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command.
MERGE INTO DW_DATA t1 USING (select 200 as file_id,'10-Jul-2018' as process_date, 'Information about row' as record_info from dual )t2 ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info) WHEN MATCHED THEN UPDATE SET file_id = t2.file_id WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info) ; Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command;
– evgeniya makarova
Nov 13 '18 at 14:21
do you mean select's result?
– evgeniya makarova
Nov 13 '18 at 14:38
The edits have improved this answer.
– KevinO
Nov 13 '18 at 14:50
add a comment |
You just need to use MERGE statement:
MERGE INTO DW_DATA t1
USING (
select 200 as file_id,
'10-Jul-2018' as process_date,
'Information about row' as record_info from dual
) t2
ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info)
WHEN MATCHED THEN UPDATE SET file_id = t2.file_id
WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info);
Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command.
You just need to use MERGE statement:
MERGE INTO DW_DATA t1
USING (
select 200 as file_id,
'10-Jul-2018' as process_date,
'Information about row' as record_info from dual
) t2
ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info)
WHEN MATCHED THEN UPDATE SET file_id = t2.file_id
WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info);
Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command.
edited Nov 13 '18 at 14:37
Adil B
3,95592338
3,95592338
answered Nov 13 '18 at 13:20
evgeniya makarovaevgeniya makarova
11
11
MERGE INTO DW_DATA t1 USING (select 200 as file_id,'10-Jul-2018' as process_date, 'Information about row' as record_info from dual )t2 ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info) WHEN MATCHED THEN UPDATE SET file_id = t2.file_id WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info) ; Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command;
– evgeniya makarova
Nov 13 '18 at 14:21
do you mean select's result?
– evgeniya makarova
Nov 13 '18 at 14:38
The edits have improved this answer.
– KevinO
Nov 13 '18 at 14:50
add a comment |
MERGE INTO DW_DATA t1 USING (select 200 as file_id,'10-Jul-2018' as process_date, 'Information about row' as record_info from dual )t2 ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info) WHEN MATCHED THEN UPDATE SET file_id = t2.file_id WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info) ; Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command;
– evgeniya makarova
Nov 13 '18 at 14:21
do you mean select's result?
– evgeniya makarova
Nov 13 '18 at 14:38
The edits have improved this answer.
– KevinO
Nov 13 '18 at 14:50
MERGE INTO DW_DATA t1 USING (select 200 as file_id,'10-Jul-2018' as process_date, 'Information about row' as record_info from dual )t2 ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info) WHEN MATCHED THEN UPDATE SET file_id = t2.file_id WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info) ; Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command;
– evgeniya makarova
Nov 13 '18 at 14:21
MERGE INTO DW_DATA t1 USING (select 200 as file_id,'10-Jul-2018' as process_date, 'Information about row' as record_info from dual )t2 ON (t1.process_date= t2.process_date and t1.record_info = t2.record_info) WHEN MATCHED THEN UPDATE SET file_id = t2.file_id WHEN NOT MATCHED THEN INSERT (file_id, process_date,recorD_info ) VALUES (t2.file_id, t2.process_date, t2.recorD_info) ; Because MERGE is designed for this purpose - update when exists and insert when not. Please check out the docs for this command;
– evgeniya makarova
Nov 13 '18 at 14:21
do you mean select's result?
– evgeniya makarova
Nov 13 '18 at 14:38
do you mean select's result?
– evgeniya makarova
Nov 13 '18 at 14:38
The edits have improved this answer.
– KevinO
Nov 13 '18 at 14:50
The edits have improved this answer.
– KevinO
Nov 13 '18 at 14:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261396%2fget-the-information-about-source-row-causing-ora-00001-unique-constraint-violat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can use
insert into ... log errors into ...
but that would not cause the insert to fail!– a_horse_with_no_name
Nov 12 '18 at 11:46
log errors will give me the information about new row i.e. row having file_id 200 if I create the ERR$ table using DBMS_ERRLOG package.
– Sanket
Nov 12 '18 at 11:49
Performance would take a hit, but you could use a merge, join the input to the source table, then use a when matched / not matched to divide the 2 scenarios up, while having access to both records.
– Andrew
Nov 12 '18 at 11:50