chalie001
asked on
create procedure with this query
hi i what to create procedure with this query
update noc_item_usrgrp
set usr_usrgrp_code = '05'
where usr_usrgrp_code = '17'
and iug_seq = 1
Error report -
ORA-00001: unique constraint (NATO.PK_NOC_ITEM_USRGRP) violated
check it therewill be duplicate if update delete the duplicate and insert in history table
delete from noc_item_usrgrp
where usr_usrgrp_code = '17'
and iug_seq = 1
and item_no = '9712788'
update noc_item_usrgrp
set usr_usrgrp_code = '05'
where usr_usrgrp_code = '17'
and iug_seq = 1
Error report -
ORA-00001: unique constraint (NATO.PK_NOC_ITEM_USRGRP) violated
check it therewill be duplicate if update delete the duplicate and insert in history table
delete from noc_item_usrgrp
where usr_usrgrp_code = '17'
and iug_seq = 1
and item_no = '9712788'
In my opinion "check it therewill be duplicate if update delete the duplicate and insert in history table " should not be done as I almost bet the whole architecture including the history table was built like this just to prevent updates that would insert duplicate rows in the history which is obviously not allowed so...unless the whole thing is flawed and this is happening just because of poor design - I would check this first instead of potentially deleting valid useful historical data just so the updated can be done.
ASKER
There is no history table
Ok, in that case where is this "unique constraint (NATO.PK_NOC_ITEM_USRGRP) violated " coming from? Obviously the update is causing that PK violation.
There is already a unique constraint associated with the table. Let the database do what it's designed to do and use the constraint to determine what's allowed and what isn't, not a separate query (and additional overhead) to see if an insert or update can be done.
BEGIN
update noc_item_usrgrp
set usr_usrgrp_code = '05'
where usr_usrgrp_code = '17'
and iug_seq = 1;
EXCEPTION
WHEN DUP_VAL_ON_INDEX
// handle the exception
WHEN PK_NOC_ITEM_USRGRP
// handle the exception
When the update is allowed, there's no additional overhead. When the update violates the constraint, it is trapped and you can move data as needed.
Good Luck!
Kent
BEGIN
update noc_item_usrgrp
set usr_usrgrp_code = '05'
where usr_usrgrp_code = '17'
and iug_seq = 1;
EXCEPTION
WHEN DUP_VAL_ON_INDEX
// handle the exception
WHEN PK_NOC_ITEM_USRGRP
// handle the exception
When the update is allowed, there's no additional overhead. When the update violates the constraint, it is trapped and you can move data as needed.
Good Luck!
Kent
I think you need to better explain what you are trying to do.
Your question and comments don't seem to match up:
and
Your question and comments don't seem to match up:
and insert in history table
and
There is no history table
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.