Question: What is
best way to import a CSV file into an Oracle table? I
have a comma delimited CSV file, and I want to rub SQL
queries against the file. What are my options for
loading my CSV?
Answer: There are several ways to query
a CSV file with SQL, by loading it into an Oracle table:
- SQL*Developer: Use the SQL
Developer wizard to load the CSV file:
1. Define the empty table. (create
table . . . . )
2. Select the table in the navigation
tree.
3. Right click and select 'import data'.
4.
Follow the instructions in the wizard.
-
SQL*Loader: Use the sqlldr utility.
See my notes on
sqlldr. That page has an example of a sqlldr
parfile to load a table from a CSV.
- External Table: Define an
external table. See my notes here on
using
an external table and
creating an external table. Here is an example
control file for defining a CSV as an external table:
create directory testdir as
'u01/oracle/oradata/testdb';
create table emp_ext (
EMPNO NUMBER(4),
ENAME
VARCHAR2(10),
JOB
VARCHAR2(9),
MGR
NUMBER(4),
HIREDATE DATE,
SAL
NUMBER(7,2),
COMM
NUMBER(7,2),
DEPTNO NUMBER(2))
Organization external
(type oracle_loader
default directory testdir
access parameters (records
delimited by newline
fields terminated by ',')
location ('emp_ext.csv'))
reject limit 1000;
Alse see
external_tables as spreadsheets.
|
|
|
Oracle Training from Don Burleson
The best on site
"Oracle
training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!
|
|
|
|
|
Burleson is the American Team
Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright © 1996 - 2020
All rights reserved by
Burleson
Oracle ®
is the registered trademark of Oracle Corporation.
|
|