ORACLE海量/批量数据导入

本文介绍了一种使用ORACLE CTL文件进行大批量数据导入的技术,通过调用系统命令实现,测试显示每秒导入约2.8万条记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原理是使用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;
        }
 以上方法仅供学习研究,有好的方法可以讨论。

 

 

 

 

 

转载于:https://www.cnblogs.com/ringwang/archive/2012/11/26/2789117.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值