你也可以使用awk。
以下是有關如何根據CSV文件中的值組合SQL查詢的詳細示例。
SQL> create table MY_TABLE(a varchar2(100), b varchar2(100));
[[email protected] ~]$ tail Some_Input_CSV_file
Some Data A 1,Some Data B 1
Some Data A 2,Some Data B 2
Some Data A 3,Some Data B 3
Some Data A 4,Some Data B 4
Some Data A 5,Some Data B 5
Some Data A 6,Some Data B 6
Some Data A 7,Some Data B 7
Some Data A 8,Some Data B 8
Some Data A 9,Some Data B 9
Some Data A 10,Some Data B 10
[[email protected] ~]$
[[email protected] ~]$ cat Some_Input_CSV_file | awk -F, ‘ { printf(「insert into MY_TABLE values(trim(\x27%s\x27), trim(\x27%s\x27));\n」, $1, $2); } ‘ > RunMe.sql
[[email protected] ~]$ tail RunMe.sql
insert into MY_TABLE values(trim(‘Some Data A 1′), trim(‘Some Data B 1′));
insert into MY_TABLE values(trim(‘Some Data A 2′), trim(‘Some Data B 2′));
insert into MY_TABLE values(trim(‘Some Data A 3′), trim(‘Some Data B 3′));
insert into MY_TABLE values(trim(‘Some Data A 4′), trim(‘Some Data B 4′));
insert into MY_TABLE values(trim(‘Some Data A 5′), trim(‘Some Data B 5′));
insert into MY_TABLE values(trim(‘Some Data A 6′), trim(‘Some Data B 6′));
insert into MY_TABLE values(trim(‘Some Data A 7′), trim(‘Some Data B 7′));
insert into MY_TABLE values(trim(‘Some Data A 8′), trim(‘Some Data B 8′));
insert into MY_TABLE values(trim(‘Some Data A 9′), trim(‘Some Data B 9′));
insert into MY_TABLE values(trim(‘Some Data A 10′), trim(‘Some Data B 10′));
[[email protected] ~]$
[[email protected] ~]$ sqlplus myuser/[email protected]
SQL> @RunMe.sql
…
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
SQL> exit
你可以在這裏使用一個外部表像這樣的例子:https://forums.oracle.com/forums/thread.jspa?threadID=545565 – Ollie 2012-04-03 08:21:59