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;
        }
 以上方法僅供學習研究,有好的方法可以討論。

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM