我在excel中使用coulmns有一些数据,我需要将这些数据从excel迁移到Oracle中的某些表。我如何以最佳和最快的方式实现这一目标。 我需要在Oracle中从该单个excel文件中加载5个表。任何可用于此类任务的工具?
答案 0 :(得分:1)
An approach could be the following.
Say you have two tables like these
create table tabA (col_a number, col_b number);
create table tabB (col_b number, col_c varchar2(10));
and you need to load data starting from a a file d:\file.csv like this:
col_a,col_b,col_c
10,99,"a"
20,999,"b c d"
you first need to create a directory, then build a table containing the CSV:
CREATE DIRECTORY dir_d AS 'D:\';
CREATE TABLE csvFile
(
Col_a VARCHAR2(4000),
Col_b VARCHAR2(4000),
Col_c VARCHAR2(4000)
)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY dir_d
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
SKIP 1
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LRTRIM
MISSING FIELD VALUES ARE NULL
)
LOCATION('file.csv'));
Now you can use SQL to insert data in your tables starting from the CSV table, using every logic you need; for example:
insert into tabA select col_a, col_b from csvFile;
insert into tabB select col_b, col_c from csvFile;
SQL> select * from tabA;
COL_A COL_B
---------- ----------
10 99
20 999
SQL> select * from tabB;
COL_B COL_C
---------- ----------
99 a
999 b c d
答案 1 :(得分:0)
如果您只想将数据放入一个表中,可以使用sqldeveloper将数据导入表中,如显示此tutorial:
答案 2 :(得分:0)
Oracle的SQL*Loader工具可以处理多表插入。如果您不想在构建适当的控制文件时遇到麻烦,可以先使用您选择的工具将数据加载到临时表中。
然后,您可以从登台表执行单个插入,或使用conditional(?)muti table insert语句。:
insert all into table_a (cola, colb, colc) values (col_a, col_b, col_c)
into table_b (cola, colb, colc, cold) values (col_a, col_b, col_c col_d)
select col_a, col_b, col_c, col_d from staging_table;
或
insert all
when col_a < 1000 then
into table_a (cola, colb, colc) values (col_a, col_b, col_c)
when col_a between 900 and 10000 then
into table_b (cola, colb, colc, cold) values (col_a, col_b, col_c col_d)
else
into table_c (cola, colb, colc, cold) values (col_a, col_b, col_c col_d)
select col_a, col_b, col_c, col_d from staging_table;
使用条件插入,每个WHEN子句的计算结果为true将导致数据被插入到指定的表中,而ELSE子句仅在没有其他选项适用时才会起作用。