<legend id='HKn8C'><style id='HKn8C'><dir id='HKn8C'><q id='HKn8C'></q></dir></style></legend>

  1. <i id='HKn8C'><tr id='HKn8C'><dt id='HKn8C'><q id='HKn8C'><span id='HKn8C'><b id='HKn8C'><form id='HKn8C'><ins id='HKn8C'></ins><ul id='HKn8C'></ul><sub id='HKn8C'></sub></form><legend id='HKn8C'></legend><bdo id='HKn8C'><pre id='HKn8C'><center id='HKn8C'></center></pre></bdo></b><th id='HKn8C'></th></span></q></dt></tr></i><div id='HKn8C'><tfoot id='HKn8C'></tfoot><dl id='HKn8C'><fieldset id='HKn8C'></fieldset></dl></div>
    <tfoot id='HKn8C'></tfoot>
      <bdo id='HKn8C'></bdo><ul id='HKn8C'></ul>
    1. <small id='HKn8C'></small><noframes id='HKn8C'>

      SQLPlus - 从 PL/SQL 块假脱机到多个文件

      时间:2023-11-03

          <small id='YOAZG'></small><noframes id='YOAZG'>

        1. <i id='YOAZG'><tr id='YOAZG'><dt id='YOAZG'><q id='YOAZG'><span id='YOAZG'><b id='YOAZG'><form id='YOAZG'><ins id='YOAZG'></ins><ul id='YOAZG'></ul><sub id='YOAZG'></sub></form><legend id='YOAZG'></legend><bdo id='YOAZG'><pre id='YOAZG'><center id='YOAZG'></center></pre></bdo></b><th id='YOAZG'></th></span></q></dt></tr></i><div id='YOAZG'><tfoot id='YOAZG'></tfoot><dl id='YOAZG'><fieldset id='YOAZG'></fieldset></dl></div>
          <tfoot id='YOAZG'></tfoot>
              <bdo id='YOAZG'></bdo><ul id='YOAZG'></ul>
                  <tbody id='YOAZG'></tbody>
                <legend id='YOAZG'><style id='YOAZG'><dir id='YOAZG'><q id='YOAZG'></q></dir></style></legend>
                本文介绍了SQLPlus - 从 PL/SQL 块假脱机到多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个将大量数据返回到 CSV 文件的查询.太多了,事实上,Excel 无法打开它 - 行太多了.有没有办法控制 spool 在每次处理 65000 行时将其假脱机到一个新文件?理想情况下,我希望在按顺序命名的文件中输出我的输出,例如 large_data_1.csvlarge_data_2.csvlarge_data_3.csv等等...

                I have a query that returns a lot of data into a CSV file. So much, in fact, that Excel can't open it - there are too many rows. Is there a way to control spool to spool to a new file everytime 65000 rows have been processed? Ideally, I'd like to have my output in files named in sequence, such as large_data_1.csv, large_data_2.csv, large_data_3.csv, etc...

                我可以在 PL/SQL 块中使用 dbms_output 来控制输出的行数,但是我将如何切换文件,因为 spool 似乎不是可以从 PL/SQL 块访问吗?

                I could use dbms_output in a PL/SQL block to control how many rows are output, but then how would I switch files, as spool does not seem to be accessible from PL/SQL blocks?

                (甲骨文 10g)

                更新:

                我无权访问服务器,因此将文件写入服务器可能无法正常工作.

                I don't have access to the server, so writing files to the server would probably not work.

                更新 2:

                某些字段包含自由格式文本,包括换行符,因此在写入文件后计算换行符不像在返回数据时计算记录那么容易...

                Some of the fields contain free-form text, including linebreaks, so counting line breaks AFTER the file is written is not as easy as counting records WHILE the data is being returned...

                推荐答案

                得到了解决方案,不知道为什么我没有早点想到这个...

                Got a solution, don't know why I didn't think of this sooner...

                基本思想是主 sqplplus 脚本生成一个中间脚本,将输出拆分为多个文件.执行中间脚本将执行多个对 rownum 施加不同范围的查询,并为每个查询假脱机到不同的文件.

                The basic idea is that the master sqplplus script generates an intermediate script that will split the output to multiple files. Executing the intermediate script will execute multiple queries with different ranges imposed on rownum, and spool to a different file for each query.

                set termout off
                set serveroutput on
                set echo off
                set feedback off
                variable v_rowCount number;
                spool intermediate_file.sql
                declare
                     i number := 0;
                     v_fileNum number := 1;
                     v_range_start number := 1;
                     v_range_end number := 1;
                     k_max_rows constant number := 65536;
                begin
                    dbms_output.enable(10000);
                    select count(*) 
                    into :v_err_count
                    from ...
                    /* You don't need to see the details of the query... */
                
                    while i <= :v_err_count loop
                
                          v_range_start := i+1;
                          if v_range_start <= :v_err_count then
                            i := i+k_max_rows;
                            v_range_end := i;
                
                            dbms_output.put_line('set colsep ,  
                set pagesize 0
                set trimspool on 
                set headsep off
                set feedback off
                set echo off
                set termout off
                set linesize 4000
                spool large_data_file_'||v_fileNum||'.csv
                select data_string
                from (select rownum rn, data_object
                      from 
                      /* Details of query omitted */
                     )
                where rn >= '||v_range_start||' and rn <= '||v_range_end||';
                spool off');
                          v_fileNum := v_fileNum +1;
                         end if;
                    end loop;
                end;
                /
                spool off
                prompt     executing intermediate file
                @intermediate_file.sql;
                set serveroutput off
                

                这篇关于SQLPlus - 从 PL/SQL 块假脱机到多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:有没有最好的方法来避免在 Oracle 中多次执行进程? 下一篇:带有 DBMS_ASSERT 的 Oracle SQL 注入块

                相关文章

                <legend id='L43ef'><style id='L43ef'><dir id='L43ef'><q id='L43ef'></q></dir></style></legend>

                • <bdo id='L43ef'></bdo><ul id='L43ef'></ul>

                <small id='L43ef'></small><noframes id='L43ef'>

                1. <i id='L43ef'><tr id='L43ef'><dt id='L43ef'><q id='L43ef'><span id='L43ef'><b id='L43ef'><form id='L43ef'><ins id='L43ef'></ins><ul id='L43ef'></ul><sub id='L43ef'></sub></form><legend id='L43ef'></legend><bdo id='L43ef'><pre id='L43ef'><center id='L43ef'></center></pre></bdo></b><th id='L43ef'></th></span></q></dt></tr></i><div id='L43ef'><tfoot id='L43ef'></tfoot><dl id='L43ef'><fieldset id='L43ef'></fieldset></dl></div>

                  <tfoot id='L43ef'></tfoot>