嗨我经常需要在表格中插入大量数据.例如,我将以excel或文本文件的形式提供数据
1,a 3,bsdf 4,sdkfj 5,something 129,else
然后我经常在这个例子中构造6个插入语句并运行sql脚本.当我必须向服务器发送数千个小包时,我发现这很慢,这也会给网络带来额外的开销.
你最好的方法是什么?
更新:我正在使用ORACLE 10g.
@R_502_323@
使用
Oracle external tables.
另见例如
> OraFaq about external tables
> What Tom thinks about external tables
> René Nyffenegger’s notes about external tables
一个简单的例子,应该让你开始
您需要一个位于服务器目录中的文件(熟悉directory objects):
sql> select directory_path from all_directories where directory_name = 'JTEST'; DIRECTORY_PATH -------------------------------------------------------------------------------- c:\data\jtest sql> !cat ~/.gvfs/jtest\ on\ 192.168.xxx.xxx/exttable-1.csv 1,else
创建外部表:
create table so13t ( id number(4),data varchar2(20) ) organization external ( type oracle_loader default directory jtest /* jtest is an existing directory object */ access parameters ( records delimited by newline fields terminated by ',' missing field values are null ) location ('exttable-1.csv') /* the file located in jtest directory */ ) reject limit unlimited;
sql> select * from so13t order by data; ID DATA ---------- ------------------------------------------------------------ 1 a 3 bsdf 129 else 4 sdkfj 5 something