[英]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.在这里,我们在 Oracle 中有一张表,我将该表数据复制到 CSV 文件中。 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. 可以使用SQL Loader(搜索“ oracle sqlldr csv”以获取信息)将CSV加载到登台表中,然后使用SQL MINUS / INTERSECT类型查询比较/报告差异。 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. 或者,使用SQLPlus假脱机(搜索“ oracle sqlplus csv spool”)将表数据提取到CSV文件中,然后在文件上使用diff。
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. 您可以编写一个存储过程,将数据提取到csv中。 Then you can compare this csv with the existing one you have. 然后,您可以将此csv与现有的csv进行比较。 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. 比较时,使用linkedhashmap存储csv,其中map的键将是数据库的主键,value是与该键对应的整行。 Now you have two map ,one for old data and another for new data. 现在,您有两个地图,一个用于旧数据,另一个用于新数据。 You comparison will be of O(1). 您的比较将为O(1)。 Cost of storage will be high but retrieval will be faster. 存储成本很高,但检索速度更快。
如果您的 CSV 文件在 DB 目录中,您可以创建外部表以从 CSV 文件中获取数据,然后进行比较
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.