简体   繁体   English

如何将 CSV 文件中的数据与 Oracle 表中的数据进行比较?

[英]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.

相关问题 将csv文件数据加载到oracle数据库中 - loading csv file data into oracle database 如何将输入与文件数据进行比较 - how to compare input with file data 试图读取 csv 数据并与 java 中的 web 表进行比较 - Trying to read csv data and compare to web table in java 如何通过java代码将CSV文件数据导入PostgreSQL表? - How to import CSV file data into a PostgreSQL table via java code? 使用java比较csv数据与oracle数据库表 - Comparing csv data with oracle database table using java 从CSV文件中读取数据,进行比较并以Java显示 - Read data from a CSV file, compare and display in Java 如何将文本文件数据与sql server表数据进行比较。 我要记录的比较记录 - How to compare a text file data with the sql server table data . The comparison i want record to record 导入csv文件以在Netbeans中的表中填充数据 - Import csv file to populate data in a table in Netbeans 如何使用Java从客户端和服务器位于不同物理系统上的csv文件上载数据到oracle中 - how to upload data into oracle from csv file where client and server are on different physical systems using java 如何使用hibernate springboot将没有header数据的csv文件加载到oracle db - How to load csv file which has no header, data into oracle db using hibernate springboot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM