Home » SQL & PL/SQL » SQL & PL/SQL » Remove duplicates when inserting !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Urgent
Remove duplicates when inserting !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Urgent [message #19501] Thu, 21 March 2002 22:11 Go to next message
Fari
Messages: 5
Registered: March 2002
Junior Member
l've tested my script and it does not work.If l insert records the first time around say from the 1st to the 2nd of
Nov 2001.It inserts into the hist table the same number of records.Then from the 3rd to the 4th, then the 5th to the
8th. If l insert the the 1st to the 2nd again l get duplicates.Where am l going wrong or how can l correct
my procedure so that it does not allow duplicates into the history table


CREATE OR REPLACE PROCEDURE Mis_Workflow_Capital (
v_start_date DATE,
v_end_date DATE,
v_num NUMBER,
v_change_date DATE
)
IS
v_cnt NUMBER;
BEGIN

insert mis_wrkflw_capital(
.....etc

-----------------------------------------------------------------------------------------------
--- Check The Mis_Wrkflw_Capital Table For Duplicates Before Insertion Into The History Table
-----------------------------------------------------------------------------------------------

v_cnt := 0;

SELECT COUNT (*)
INTO v_cnt
FROM Mis_Wrkflw_Cap_Hist
WHERE TO_DATE (v_change_date, 'yyyy-mm-dd HH24:MI:SS') =
TO_DATE (change_date, 'yyyy-mm-dd HH24:MI:SS')
AND SYSDATE = TO_DATE (summary_date, 'yyyy-mm-dd HH24:MI:SS');

IF v_cnt = 0
THEN
INSERT INTO Mis_Wrkflw_Cap_Hist
(num, branch, sbrokercd, received, rec_count, prequota,
prequota_count, batched, batched_count, scanned_received,
scanrec_count, captured, cpa_count, checked, chkd_count,
rules, rules_count, returned, ret_count, disburse,
dis_count, active, active_count, pre_reject, prerej_count,
rejected, rej_count, summary_date, change_date)

SELECT v_num, branch, sbrokercd, received, rec_count, prequota,
prequota_count, batched, batched_count, scanned_received,
scanrec_count, captured, cpa_count, checked, chkd_count,
rules, rules_count, returned, ret_count, disburse, dis_count,
active, active_count, pre_reject, prerej_count, rejected,
rej_count, summary_date, change_date
FROM Mis_Wrkflw_Capital;
END IF;

COMMIT;
END;
Re: Remove duplicates when inserting !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Urgent [message #19508 is a reply to message #19501] Fri, 22 March 2002 07:13 Go to previous messageGo to next message
oraboy
Messages: 97
Registered: October 2001
Member
Remove the time component off while comparing with dates.

HTH
oraboy
Re: Remove duplicates when inserting !!!!!Still not working !!!Urgent [message #19526 is a reply to message #19508] Sun, 24 March 2002 11:53 Go to previous messageGo to next message
Fari
Messages: 5
Registered: March 2002
Junior Member
tried that and it works but the problem is that because l've removed time in the dates it will now not insert records into the history table because the date is the same and there is no time comparison.Is there another way to code the potion of my procedure???
Re: Remove duplicates when inserting !!!!!Still not working !!!Urgent [message #19540 is a reply to message #19508] Tue, 26 March 2002 09:29 Go to previous messageGo to next message
oraboy
Messages: 97
Registered: October 2001
Member
I dont understand what you are coming to say.
Can you give me an example script simulating ur situation..

oraboy
Re: Remove duplicates when inserting !!!!!Still not working !!!Urgent [message #19546 is a reply to message #19508] Tue, 26 March 2002 19:18 Go to previous message
Fari
Messages: 5
Registered: March 2002
Junior Member
maybe the best way out of this one is to have a trigger that removes duplicates on insert.How would l code that?
Previous Topic: Wnated to Create a back up tool
Next Topic: regarding file access in pl/sql procedure
Goto Forum:
  


Current Time: Fri Apr 26 17:52:05 CDT 2024