使用 for 循环假脱机到 .csv 文件 [英] spool to .csv file using for loop

查看:77
本文介绍了使用 for 循环假脱机到 .csv 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要使用循环将输出假脱机到 .csv 文件中,仅供参考...我在 4 个差异分区中有数据.

need to spool output into .csv file using loop, fyi...I have data in 4 diff partition.

但不知道如何继续.

代码就像.

begin
FOR var_1 in 1 .. 4
LOOP
set linesize 1000
set feedback off
set underline off
spool C:\Users\file.csv replace
        SELECT cust_no FROM customer PARTITION (customer_PR'||var_1||')
        WHERE city='ba' AND first_name='john'
        AND salary=1000;
spool off;
END LOOP;
END;
/

结果:-

Error report -
ORA-06550: line 4, column 5:
PL/SQL: ORA-00922: missing or invalid option
ORA-06550: line 4, column 1:
PL/SQL: SQL Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

不确定我是否正确假脱机,还请检查在我的 select 语句中正确使用的 for 循环的索引变量.

not sure if I am spooling properly, also please check the index variable of for loop in used correctly in my select statement.

推荐答案

您不需要 4 个不同的查询,只需在查询中列出您的所有分区:

You don't need 4 different queries, just list all your partitions in the query:

set linesize 1000
set feedback off
set underline off
spool C:\Users\file.csv replace
SELECT cust_no FROM customer PARTITION (customer_PR1, customer_PR2, customer_PR3, customer_PR4)
        WHERE city='ba' AND first_name='john'
        AND salary=1000;
spool off;

这篇关于使用 for 循环假脱机到 .csv 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆