Oracle Bulk Import

旧巷老猫 提交于 2019-12-02 11:37:38

问题


Bulk Import in Oracle

I have created the table emp and I need to import bulk data from a file into emp

For Ex

CREATE TABLE emp

( c1 NUMBER,

  c2 VARCHAR2(30)

)

File path : 'C:\Documents and Settings\TestUser\My Documents\LearnOracle\reports.csv'


回答1:


You will have to use the inbuilt tool sql*loader to load data from external flat files into oracle.
1. create a control file control.ctl

  load data
  infile 'reports.csv' 
  into table emp
  fields terminated by ',' optionally
  enclosed by '"'
  c1,c2

2. data file is your reports.csv

3.invoke sql*loader: $ sqlldr scott/tiger control=control.ctl
Note: this is the name of the control file that you have made




回答2:


Write a Control file, say emp.ctl

load data
 options(direct=true)
insert
 into table emp
fields terminated by ',' optionally enclosed by '"' TRAILING NULLCOLS
 ( 
    c1 DECIMAL EXTERNAL,
    c2
)

Execute SQL*Loader as below.

sqlldr userid=user/pass@db data=reports.csv control=emp.ctl 

If you always want to refresh the table with your data completely. TRUNCATE the table and then load.

SQL*Loader is great utility that provide numerous options for performance. Kindly go through the documentation about DIRECT and CONVENTIONAL loading.

There's something called EXTERNAL tables, that might interest you as well. They use the flat file for the table data.



来源:https://stackoverflow.com/questions/22241428/oracle-bulk-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!