Oracle PL-SQL:将多个分隔文件导入表中
我有多个文件(f1.log、f2.log、f3.log 等) 每个文件都有 ;
& 中的数据。 =
分隔格式。 (新行由 ;
分隔,字段由 =
分隔)例如
f1 的数据:
1=a;2=b;3=c
f2 的数据:
1=p;2=q;3=r
我需要读取所有这些文件并将数据导入到表中格式:
filename number data
f1 1 a
f1 2 b
f1 3 c
f2 1 p
[...]
我是 SQL 新手。您能指导一下吗,该怎么办?
I have multiple files (f1.log, f2.log, f3.log etc)
Each file has the data in ;
& =
delimited format. (new lines are delimited by ;
and fields are delimited by =
) e.g.
data of f1:
1=a;2=b;3=c
data of f2:
1=p;2=q;3=r
I need to read all these files and import data into table in format:
filename number data
f1 1 a
f1 2 b
f1 3 c
f2 1 p
[...]
I am new to SQL. Can you please guide me, how can do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 SQL*Loader 将文件放入表中。假设您创建了一个类似于以下内容的表:
那么您可以使用以下控制文件:
但是,每个文件都需要不同的控制文件。这可以通过使用 shell 脚本动态创建控制文件来完成。示例 shell 脚本可以是:
保存为
flog.sh
然后可以像这样运行:Use SQL*Loader to get the files into a table. Assuming you have a table created a bit like:
Then you can use the following control file:
However, you will need a different control file for each file. This can be done by making the control file dynamically using a shell script. A sample shell script can be:
Saved as
flog.sh
it can then be run like: