Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below are the details of my query.
Processing of data goes as below
I have Data in .csv file.--> through procedure---> Data from .csv gets stored into revenue table.

Table structure
ID----Varchar2 
Name--> Varchar2 
Revenue_Amount--> number
Upd_dt--->date (sysdate)


Data file(.csv) structure
Acct-OCT-15,  NAME,  RevenueAmount,
11111190778,  ABC,   100000
11111119877,  ABC1,  200020 

Issue: We need to load the file record monthly. But if the duplicate file will come we need to identify and stop the processing of the file.
In data file header first row can be taken as identifier but I am not sure how do I implement this scenario.

Will receive data file on monthly basis. Please don't hesistate to ask if question is not clear
Posted
Updated 18-Dec-15 18:53pm
v2
Comments
Mehdi Gholam 19-Dec-15 1:46am    
What have you done so far?
Member 10431234 19-Dec-15 7:59am    
I have created a procedure and inserted the records into the table.
It looks like as below
Procedure
--------------
create or replace procedure revenue_sp
(
ID VArchar2
Name Varchar2,
Revenue_Amount number,
Upd_dt date,
v_out Out Varchar2);
as
l_ID t_revenue.ID%TYPE;
l_Name t_revenue.ID%TYPE;
l_Revenue_Amount t_revenue.ID%TYPE;
l_Upd_dt t_revenue.ID%TYPE;
IS
BEGIN
l_Upd_dt :=sysdate ;
insert into t_revenue
(
ID ,
Name ,
Revenue_Amount ,
Upd_dt
)
Values
(
l_ID ,
l_Name ,
l_Revenue_Amount ,
l_Upd_dt
)
commit;
END;

Table
----------
ID Name Revenue_Amount Upd_dt
11111190778 ABC 100000 19-Dec-2015
11111119877 ABC1 200020 19-Dec-2015

1 solution

1) better way to avoid duplicates is by creating a temp table with same structure name RevenueTemp
SQL
CREATE TABLE RevenueTemp 
AS SELECT * FROM Revenue where 1=0
and first time load your .csv file in this Temp table after completing use below query to insert from temp table to main table
SQL
Insert into Revenue
Select * from RevenueTemp a left outer join Revenue b on a.id=b.id where b.id is null

And i hope your id in Revenue Table is set as Primary Key.

2)You can create one header table with column ID,FileName and before processing complete file you can first check in this table
SQL
SELECT * FROM HeaderTable WHERE FileName='Acct-OCT-15'

if no data found then insert first line in HeaderTable and rest in your detail table with id as foreign key
 
Share this answer
 
v4
Comments
Member 10431234 20-Dec-15 9:07am    
Thanks Awad. Yes ID and name combination are primary key. But I don't bother about content of the datafile now. I want to get notified if header of the datafile has changed(i.e Acct-OCT-15 field only). I am trying to find a way to add a indicator field in our table based on the ACC-MON-15 field in .csv header. Whenever I will get .csv monthly , ACCT-MON-15 field alone will change.
Basmeh Awad 20-Dec-15 9:22am    
Check second point

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900