简体   繁体   English

将多个表数据从SQL Server迁移到Oracle

[英]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或任何其他编程语言吗?

C# approach - SchemaMapper library C#方法-SchemaMapper库

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中添加问题


Other approach - SQL Server Import and Export Wizard 其他方法-SQL Server导入和导出向导

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: 脚步:

  1. Dump the SQL tables data into flat files.(Used BIML for automating the DFT creation) 将SQL表数据转储到平面文件中(使用BIML自动执行DFT创建)
  2. Transfer these flat files to the Destination server. 将这些平面文件传输到目标服务器。
  3. Using SQL*Loader to load data from flat files to Oracle. 使用SQL * Loader将数据从平面文件加载到Oracle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从多个 SQL 表中提取数据以用于多个输出 - How to extract data from multiple SQL tables in one for multiple outputs 使用python从oracle数据库中的多个表中获取数据并将这些数据插入到另一个表中 - Fetch data from multiple tables from oracle database using python and insert those data into another table Python 和 SQL 交互:从 GUI 查询多个表和插入数据 - Python and SQL Interactions: Query Multiple Tables & Insert Data from GUI SQL 从 2 个表插入数据 - SQL INSERT data from 2 tables Python 插入oracle数据到sql服务器 - Python insert oracle data into sql server 从多个结果集中获取数据 - SQL 服务器到 Python - Fetch data from multiple result sets - SQL Server to Python 根据来自多个其他表的数据动态生成 SQL Insert Rows 数据 - Generate SQL Insert Rows data dynamically based on data from multiple other tables 将所有数据从 Oracle 11.2 迁移到 SQL Server 2012 的最佳方法是什么? - What is the best way to migrate all data from Oracle 11.2 to SQL Server 2012? 仅当脚本使用python返回数据时,如何将结果从多个Oracle sql脚本导出到csv - How to export the results from multiple oracle sql scripts to csv only when the script returns data using python SQL 查询从 2 个表中获取数据 - SQL query to fetch data from 2 tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM