简体   繁体   English

将数据从Oracle表传输到文本文件

[英]Transfer data from Oracle table to text file

I'm interested is it possible with PL/SQL block to transfer the content of a Oracle table into text file on the Hard Drive. 我感兴趣的是PL / SQL块可以将Oracle表的内容传输到硬盘上的文本文件中。 I need a PL/SQL block which can download the content of a table witch will be used to store log data into text file. 我需要一个PL / SQL块,它可以下载一个表的内容,用于将日志数据存储到文本文件中。

Regards 问候

you can use UTL_file package for this.. 你可以使用UTL_file包这个..

you can try below type of block -- 你可以尝试以下类型的块 -

declare 
p_file util_file.file_type;
l_table <your_table_name>.ROWTYPE;
l_delimited varchar2(1) := '|';
begin
p_file:= utl_file.fopen('<file_path>','<file_name>','W');
for l_table in (select * from <your_table_name>) loop
utl_file.putline(p_file,l_table.col1||l_delimited||l_table.col2||l_delimited||l_table.col3||l_delimited||l_table.col4||l_delimited <continue with column list .........> ||chr(10));
end loop;    
utl_file.fclose_all();
end;

pratik garg's answer is a good one. pratik garg的答案很好。
But, you might want to consider also the use of an EXTERNAL TABLE . 但是,您可能还想考虑使用EXTERNAL TABLE
Basically, it's a table which is mapped to a file. 基本上,它是一个映射到文件的表。 So every row inserted to the table is automatically written to a file. 因此,插入表中的每一行都会自动写入文件。
you can see an example here 你可以在这里看到一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM