zoukankan      html  css  js  c++  java
  • ORACLE海量/批量数据导入

    原理是使用ORACLE的CTL文件,然后用系统的命令直接调用导入。

    测试过导入几百个文件,220分钟导入3.7亿条,每秒大概2.8万条。

    1.CTL文件模板

    LOAD DATA  
    INFILE '<!--input file name-->'
    APPEND INTO TABLE STAT_PVTEMP
    FIELDS TERMINATED BY '|'
    (Email,ClientIP,Tstamp,URL)

    2.用服务程序调用目标文件夹下的文件,然后按照CTL文件模板生成文件。

    取相应的配置信息:

            static string downloadFilePath = System.Web.Configuration.WebConfigurationManager.AppSettings["DownloadFilePath"].ToString();
            static string ctlTemplateFile = System.Web.Configuration.WebConfigurationManager.AppSettings["CtlTemplateFile"].ToString();
            static string batTemplateFile = System.Web.Configuration.WebConfigurationManager.AppSettings["BatTemplateFile"].ToString();
            static string exeTemplatePath = System.Web.Configuration.WebConfigurationManager.AppSettings["ExeTemplatePath"].ToString();
     生成导入文件的执行命令:
    string batCmd = "sqlldr   userid=用户ID/密码@服务   control="+ctlFilePath+"   log="+logFilePath+"  bad="+badFilePath+" errors=1000";

    执行的命令的函数:

    public static string ExeCommand(string commandText)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                string stroutput = null;
                try
                {
                    p.Start();
                    p.StandardInput.WriteLine(commandText);
                    p.StandardInput.WriteLine("exit");
                    stroutput = p.StandardOutput.ReadToEnd();
                    p.WaitForExit();
                    p.Close();
                }
                catch (Exception ex)
                {
                    stroutput = ex.Message;
                }
                return stroutput;
            }
     以上方法仅供学习研究,有好的方法可以讨论。 
  • 相关阅读:
    对于在git上面拉代码报"error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054"解决方法
    在vue项目中如何添加eslint
    vscode编辑如何保存时自动校准eslint规范
    css3动画
    JS中的深拷贝与浅拷贝
    JS中的防抖与节流
    金三银四求职季,前端面试题小梳理(HTML、CSS、JS)
    正则表达式元字符大整理
    常规正则表达式练习,一起来开心的掉发吧
    关于子元素的margin-top对父级容器无效
  • 原文地址:https://www.cnblogs.com/ringwang/p/2789117.html
Copyright © 2011-2022 走看看