简体   繁体   中英

How to compare the Data in CSV file with Data in the Oracle table?

Here we are having one table in Oracle and i have copies that table data into CSV file. Now we have to compare whether data is correct or not.

Either, use SQL Loader (search for "oracle sqlldr csv" for info) to load the CSV into a staging table then use SQL MINUS/INTERSECT type queries to compare/report diffs. Or, extract the table data into a CSV file using SQLPlus spool (search for "oracle sqlplus csv spool" ) and then use diff on the files.

My advice is the first approach as that will make it easier to do any further processing of the data.

You can write a stored procedure that will fetch data into csv. Then you can compare this csv with the existing one you have. While comparing ,use linkedhashmap to store the csv where key of map will be primary key of your database and value will be entire row corresponding with that key. Now you have two map ,one for old data and another for new data. You comparison will be of O(1). Cost of storage will be high but retrieval will be faster.

如果您的 CSV 文件在 DB 目录中,您可以创建外部表以从 CSV 文件中获取数据,然后进行比较

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM