我想在sqlplus或SQLCL中每周提取相同的查询,也许在Windows服务器上安排任务,在csv文件中使用帐户代码的名称和日期进行假脱机。 我写了下面的脚本,它有效,但我有两个问题。
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
COL VPATH NEW_VALUE NEW_VPATH;
COL PRESIDIO NEW_VALUE NEW_PRESIDIO;
COL SEPARATORE NEW_VALUE NEW_SEPARATORE;
COL DATA NEW_VALUE NEW_DATA;
COL EXT NEW_VALUE NEW_EXT;
SET SQLFORMAT CSV;
SELECT 'C:\Shared_Folder\' VPATH, 'AO_GALLARATE' PRESIDIO,'_' SEPARATORE, TO_CHAR(CURRENT_DATE) DATA,'.CSV' EXT FROM DUAL;
SET FEEDBACK ON;
SET TERMOUT OFF;
SPOOL "&NEW_VPATH&NEW_PRESIDIO&NEW_SEPARATORE&NEW_DATA&NEW_EXT";
SELECT /*CSV*/ SERIAL_NUMBER, DNS_HOST_NAME, IP_ADDRESS, MODEL_NAME, TOTAL_PAGE_COUNT - COLOR_PAGE_COUNT, COLOR_PAGE_COUNT, TRUNC(LAST_DATA_COLLECTION) FROM DEVICE WHERE ACCOUNT_CODE = '&NEW_PRESIDIO' AND model_name LIKE '%MS410%';
ORDER BY SERIAL_NUMBER ASC;
SPOOL OFF;
我在哪里以及我做错了什么?
答案 0 :(得分:0)
可能没什么。这与@ruudvan所说的重复有点不同。您应该能够像在执行此操作时那样在spool命令上使用替换。
这是早期版本中的一个错误。在SQLcl的最新版本中,我试过这个并且看起来效果很好。
(~/qa) $cat subnew.sql
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
COL VPATH NEW_VALUE NEW_VPATH;
COL PRESIDIO NEW_VALUE NEW_PRESIDIO;
COL SEPARATORE NEW_VALUE NEW_SEPARATORE;
COL DATA NEW_VALUE NEW_DATA;
COL EXT NEW_VALUE NEW_EXT;
COL USER NEW_VALUE NEW_USER;
SET SQLFORMAT CSV;
SELECT './' VPATH, 'AO_GALLARATE' PRESIDIO,'_' SEPARATORE, TO_CHAR(CURRENT_DATE) DATA,
'.CSV' EXT , USER FROM DUAL;
SET FEEDBACK OFF;
SET TERMOUT OFF;
SPOOL "&NEW_VPATH&NEW_PRESIDIO&NEW_SEPARATORE&NEW_DATA&NEW_EXT";
select /* csv */ * from substitution
where upper(name) = '&NEW_USER';
SPOOL OFF;
exit
(~/qa) $sql barry/oracle @subnew
SQLcl: Release 12.2.0.1.0 RC on Tue Aug 09 13:21:28 2016
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Last Successful login time: Tue Aug 09 2016 13:21:29 +01:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
"VPATH","PRESIDIO","SEPARATORE","DATA","EXT","USER"
"./","AO_GALLARATE","_","09-AUG-16",".CSV","BARRY"
(~/qa) $ls -altr AO_GALLARATE_09-AUG-16.CSV
-rw-r--r-- 1 bamcgill staff 22 9 Aug 13:21 AO_GALLARATE_09-AUG-16.CSV
(~/qa) $cat AO_GALLARATE_09-AUG-16.CSV
"ID","NAME"
1,"Barry"
(~/qa) $