如何将oracle查询结果输出到windows中的文本文件中?

时间:2017-09-14 21:43:19

标签: database oracle

查询将生成大数据集 (4列和~600万行)。我尝试了下面的查询较小的数据,但它将查询本身写入文本文件而不是查询结果:

spool test.txt
SELECT a.ID, a.COLOR,a.TYPE,b.DESC
FROM TABLE_1 a
left join TABLE_2 b on a.ID=b.ID
spool off

从Oracle数据库中提取上述数据的最有效方法是什么?我将在Production数据库中运行查询,并希望以最有效的方式提取数据。除了spool函数之外,还有什么可以尝试的吗?

2 个答案:

答案 0 :(得分:0)

创建Oracle目录并使用UTL_FILE将文件写入其中。

如果有任何进一步的澄清,请不要犹豫再次与我联系!

泰德

e.g。

create directory logfile as 'd:\logfile'; -- must have priv to do this

declare
  vFile utl_file.file_type;
begin
  vFile := utl_file.fopen(logfile ,'syslog','w'); -- w is write. This returns file handle
  utl_file.put(vFile,'Start Logfile'); -- note use of file handle vFile
  utl_file.fclose(vFile); -- note use of file handle vFile
end;

答案 1 :(得分:0)

最快的方式是bulk export.

formatData: function () {
    var graphData = [],
        xValue = 0;

    var savingsPerYear = _.reduce(calculated.yearlyData, function (agg, year) {
        agg.push({ x: xValue, y: biddle_helpers.roundNumber(year.saved_energy_price, 0) });
        xValue++;
        return agg;
    }, []);

    var investment = [],
        purchaseCost = input_values.get('product_purchase_cost') + input_values.get('product_installation_cost');
    for (var i = 0; i <= input_values.get('product_lifetime'); i++) {
        investment.push({ x: i, y: purchaseCost });
    }

    graphData.push({
        values: savingsPerYear,
        key: 'Savings per year',
    });
    graphData.push({
        values: investment,
        key: 'Investment',
        classed: 'dashed'
    });

    return graphData;
}