[英]Migrating multiple tables data from SQL Server to Oracle
I have a scenario to migrate SQL Server tables(30- 40 tables) to Oracle. 我有一个将SQL Server表(30-40个表)迁移到Oracle的方案。 I Cannot depend on SSIS as the no of tables to be migrated to Oracle will change regularly and I cannot always create or update a DFT when ever there is a change in schema.
我不能依赖SSIS,因为要迁移到Oracle的表的数目会定期更改,并且架构发生变化时,我也不能始终创建或更新DFT。 Is there any other way where the movement of data can be handled dynamically and can work effectively ?
还有其他方法可以动态处理数据移动并使其有效工作吗? Like using Python or any other Programming languages ?
喜欢使用Python或任何其他编程语言吗?
Since you are open to a solution using a programming language, i think you can benefit from SchemaMapper class library which is an open-source project published on GitHub. 由于您对使用编程语言的解决方案持开放态度 ,因此我认为您可以从SchemaMapper类库中受益,该类库是在GitHub上发布的一个开源项目。 A full description can be found in the Readme file on the link above.
在上面的链接的自述文件中可以找到完整的描述。
Important Note: Yesterday i added the support of reading data from databases (SQL Server , Oracle ...) and the ability to export data to Oracle. 重要说明:昨天,我增加了从数据库(SQL Server,Oracle ...)读取数据的支持以及将数据导出到Oracle的功能。
In this answer i will provide information on importing SQL Server tables, create the appropriate SchemaMapper class for each one (since they have different schema and you need to import them to different schemas) , and how to export data to Oracle. 在此答案中,我将提供有关导入SQL Server表,为每个表创建适当的SchemaMapper类的信息(因为它们具有不同的架构,并且您需要将它们导入到不同的架构) ,以及如何将数据导出到Oracle。
//First of all list the tables names need to import
string[] TableNameFilter = new[] { "Table1", "Table2" };
//Create an instance of the oracle import class
SchemaMapper.Exporters.OracleExport expOracle = new SchemaMapper.Exporters.OracleExport(oracleconnectionstring);
//Create an SQL Server import class
using (SchemaMapper.Converters.SqlServerCeImport ssImport = new SchemaMapper.Converters.SqlServerCeImport(sqlconnectionstring))
{
//Retrieve tables names
ssImport.getSchemaTable();
//loop over tables matching the filter
foreach(DataRow drRowSchema in ssImport.SchemaTable.AsEnumerable().Where(x =>
TableNameFilter.Contains(x["TABLE_NAME"].ToString())).ToList())
{
string SQLTableName = drRowSchema["TABLE_NAME"].ToString();
string SQLTableSchema = drRowSchema["TABLE_SCHEMA"].ToString();
DataTable dtSQL = ssImport.GetDataTable(SQLTableSchema, SQLTableName);
//Create a schema mapping class
using (SchemaMapper.SchemaMapping.SchemaMapper sm = new SchemaMapper.SchemaMapping.SchemaMapper(SQLTableSchema, SQLTableName))
{
foreach (DataColumn dc in dtSQL.Columns)
{
SchemaMapper_Column smCol = new SchemaMapper_Column();
smCol.Name = dc.ColumnName;
smCol.Name = dc.ColumnName;
smCol.DataType = smCol.GetCorrespondingDataType(dc.DataType.ToString(), dc.MaxLength);
sm.Columns.Add(smCol);
}
//create destination table in oracle
expOracle.CreateDestinationTable(sm);
//Insert data
expOracle.InsertUsingOracleBulk(sm, dtSQL);
//there are other methods such as :
//expOracle.InsertIntoDb(sm, dtSQL);
//expOracle.InsertIntoDbWithParameters(sm, dtSQL);
}
}
}
Note: this is an open-source project: it is not fully tested and not all data types are supported, if you encountered some errors feel free to give a feedback, or add an Issue in GitHub 注意:这是一个开源项目:尚未经过全面测试,也不支持所有数据类型,如果遇到一些错误,请随时提供反馈或在GitHub中添加问题
If you can do this without scheduling a Job, then you can use the Import and Export Wizard which allows you to import multiple tables into Oracle without the need to build the packages manually. 如果可以在不计划作业的情况下执行此操作,则可以使用“导入和导出向导”,该向导允许您将多个表导入Oracle,而无需手动构建软件包。 It will create packages, destination tables, map columns and import data.
它将创建包,目标表,映射列和导入数据。
Here is the approach I have decided to go considering the time constraint( using C# is taking more time).For 8 GB table it is taking 11 minutes to move the data SQL to Oracle. 这是我决定考虑时间限制的方法(使用C#会花费更多时间)。对于8 GB的表,将数据SQL移至Oracle需要11分钟。
Steps: 脚步:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.