如何将Oracle表导出到制表符分隔的值? [英] How can I export an Oracle table to tab separated values?
本文介绍了如何将Oracle表导出到制表符分隔的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将数据库中的表导出到制表符分隔的值文件中。我在Perl和SQL Plus上使用DBI。它是否支持(DBI或SQL Plus)到TSV文件的导入和导出?
I need to export a table in the database to a tab separated values file. I am using DBI on Perl and SQLPlus. Does it support (DBI or SQLPlus) exporting and importing to or from TSV files?
我可以编写代码来满足需要,但是我想使用现成的解决方案(如果有)。
I can write a code to do my need, But I would like to use a ready made solution if it is available.
推荐答案
将表转储到带有制表符分隔值的文件中应该相对简单。
It should be relatively simple to dump a table to a file with tab-separated values.
例如:
open(my $outputFile, '>', 'myTable.tsv');
my $sth = $dbh->prepare('SELECT * FROM myTable');
$sth->execute;
while (my $row = $sth->fetchrow_arrayref) {
print $outputFile join("\t", @$row) . "\n";
}
close $outputFile;
$sth->finish;
请注意,如果您的数据包含制表符或换行符,此方法将无法正常工作。
Note that this will not work well if your data contains either a tab or a newline.
这篇关于如何将Oracle表导出到制表符分隔的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文