sql - 使用 for 循环假脱机到 .csv 文件
问题描述
需要使用循环将输出假脱机到 .csv 文件中,仅供参考...我在 4 个 diff 分区中有数据。
但不知道如何进行。
代码就像。
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:
不确定我是否正确假脱机,还请检查在我的选择语句中正确使用的 for 循环的索引变量。
解决方案
您不需要 4 个不同的查询,只需在查询中列出所有分区:
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;
推荐阅读
- android - 如何分别保存多张选定的照片以上传到android studio中的服务器?
- java - 为什么 Files.walk(path, FileVisitOption.FOLLOW_LINKS) 不关注链接?
- php - Laravel 事务与逻辑
- php - 我想从私有对象中获取用户 ID 值
- c# - 如何在 C# 中的对象内设置多个属性值?
- javascript - 如何使用 package.json 运行 ts 脚本?
- java - 根据日期对 JSON 进行排序
- ios - 如果未在其中调用给定函数,Swift如何触发回调
秒? - c++ - 为什么我可以在作为返回 const 对象函数的结果的 const 对象中改变成员变量?
- css - React & Rails - Bootstrap 样式已投入生产