将 CSV 文件加载到 Oracle 表中

发布于 2024-10-03 16:34:50 字数 71 浏览 1 评论 0原文

我正在使用 Oracle ApEx,我想知道将单列 csv 文件上传到 Oracle 表以在 ApEx 中使用的最佳方法是什么?

I am using Oracle ApEx and I was wondering on what is the best way to upload a single column csv file into an Oracle table, to be used within ApEx?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

摇划花蜜的午后 2024-10-10 16:34:50

我和你有同样的问题。
您可能已经找到了解决方案,但我按照此链接中的方法操作
http://forums.oracle.com/forums/thread.jspa?threadID=545565
这对我有用。他们使用外部表。最大列数为 50。

其他选项为 http://avdeo.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
但是,我发现如果您的 CSV 包含一些特殊字符,它就无法正常运行。

希望这会有所帮助。

I had the same issues as you.
You probably already found the solution but I follow the method in this link
http://forums.oracle.com/forums/thread.jspa?threadID=545565
and it works for me. They used external tables. The maximum number of columns is 50.

Other option is http://avdeo.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
However, I found that if your CSV contains some special character, it does not run properly.

Hope this helps somehow.

狼亦尘 2024-10-10 16:34:50

要使用 SQLLOADER 加载 CSV 文件,您需要执行以下操作:

(a) CSV 文件
(b) SQLLOADER控制文件(也称为CTL文件)
(c) SQLLOADER 命令使用 (b) 中的 CTL 文件加载 (a) 中的 CSV 文件。

CSV 文件,您已经有了。对于本示例,文件名为 temp.csv,包含两列

A,100
B,200
C,300
D,400

现在,您需要创建一个控件来描述该文件以及将其加载到哪个表以及如何加载。对于本例,控制文件名为 temp.ctl,您要加载的表是 TEMP_TABLE,它包含两列,COLUMN_1 是 VARCHAR2(2),COLUMN_2 是 NUMBER。 temp.ctl 如下所示

LOAD DATA
APPEND
INTO TEMP_TABLE
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
  COLUMN_1 CHAR,
  COLUMN_2 Integer EXTERNAL
)

To load a CSV file using SQLLOADER you will need to do the following:

(a) The CSV file
(b) SQLLOADER Control file (also known as CTL file)
(c) SQLLOADER command to use the CTL file in (b) to load the CSV file in (a).

CSV file, you already have that. For this example, the file name is temp.csv contains two columns

A,100
B,200
C,300
D,400

Now, you need to create a control to describe the file and which table to load it to, and how to load it. For this example, the control file name called temp.ctl and the table you want to load into is TEMP_TABLE that contains two columns, COLUMN_1 is VARCHAR2(2), COLUMN_2 is NUMBER. The temp.ctl looks like the below

LOAD DATA
APPEND
INTO TEMP_TABLE
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
  COLUMN_1 CHAR,
  COLUMN_2 Integer EXTERNAL
)
和影子一齐双人舞 2024-10-10 16:34:50

大文件:

  • sqlloader
  • 外部表

小文件:

  • 自己解析

Big files:

  • sqlloader
  • external tables

Small files:

  • own parsing
勿挽旧人 2024-10-10 16:34:50

你可以用 awk 来完成。

以下是有关如何从 .csv 数据填充表的示例。

SQL> create table MY_TABLE(a varchar2(100), b varchar2(100));

[oracle@myora ~]$ 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
[oracle@myora ~]$

[oracle@myora ~]$ 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

[oracle@myora ~]$ 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′));
[oracle@myora ~]$

[oracle@myora ~]$ sqlplus myuser/mypwd@myinst

SQL> @RunMe.sql

…

1 row created.

1 row created.

1 row created.

1 row created.

1 row created.

SQL> commit;

Commit complete.

SQL> exit

You can do it with awk.

Here is example on how to populate table from .csv data.

SQL> create table MY_TABLE(a varchar2(100), b varchar2(100));

[oracle@myora ~]$ 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
[oracle@myora ~]$

[oracle@myora ~]$ 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

[oracle@myora ~]$ 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′));
[oracle@myora ~]$

[oracle@myora ~]$ sqlplus myuser/mypwd@myinst

SQL> @RunMe.sql

…

1 row created.

1 row created.

1 row created.

1 row created.

1 row created.

SQL> commit;

Commit complete.

SQL> exit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文