如何将文本文件中数据导入到SQL表中 ?

如题所述

1、创建load.ctl文件:

在任意文件夹下创建load.ctl文件,用编辑器打开load.ctl文件,并写入以下代码:

loaddata

CHARACTERSETUTF8  

infile"D:\importdata\datafile\data.txt" 

append

intotabletable_name

fieldsterminatedby'|'

trailingnullcols

(

id,

mobile

)

2、运行load.ctl文件:打开cmd,切换到load.ctl文件目录下,运行以下命令:

sqlldrsuncrs/suncrs@ubuatcontrol=load.ctllog=log.log

suncrs为用户名和密码,ubuat为数据库名

扩展资料:

load.ctl代码解析:

第二行指定编码(文本文件编码)。

第三行指定要导入的文件data.txt的路径。

第五行指定导入的表(以上l例子表名为:table_name)。

第六行表示字段分隔符。

最后括号内填写字段(注意顺序),字段名写目标表的字段名。

温馨提示:答案为网友推荐,仅供参考
相似回答