0

使用 SQL Plus,我运行这个脚本

set colsep ,
set headsep off
set pagesize 0
set trimspool on
set linesize 67
set numwidth 20

spool C:\Users\xxxxx\AppData\Local\Temp\bncm.txt

SELECT
UNIQ_ID AS UNIQUEID
,REC_ID AS REC_ID
,ACC_NUM AS ACCOUNT
,NOTE_NUM AS NOTENMB
... more columns here
from visn_exp.V_IHCVSN_COMML_LN
WHERE as_of_dt = '30-oct-2020';

spool off

像这样:

运行 sqlplus 的屏幕截图

但是当我这样做时,这些行显示在控制台上,而不是写入文件中。我错过了什么?

更新:简单测试

> sqlplus svc_visn_rrdw@usrrprd

SQL*Plus: Release 12.2.0.1.0 Production on Wed Jan 27 13:51:47 2021

Copyright (c) 1982, 2017, Oracle.  All rights reserved.

Enter password:
Last Successful login time: Wed Jan 27 2021 13:26:03 -05:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options

SQL> spool c:\temp\dual.txt
SQL> select * from dual;

D
-
X

SQL> spool off
SQL>

PS P:\
> cat c:\temp\dual.txt
SQL> select * from dual;

D
-
X

SQL> spool off

PS P:\
>

从 cmd 而不是 Posh 运行时,结果与上述相同。查询结果出现在控制台(和目标文件)中。我想停止结果出现在控制台中。

4

1 回答 1

0

使用 SQL*Plus 命令set termout off禁用控制台输出。但是,该命令仅适用于脚本 - 您必须将命令放在脚本中,而不是简单地输入所有命令。

例如,使用以下内容创建文件“C:\temp\test.sql”:

set termout off
spool c:\temp\dual.txt
select * from dual;
spool off

当您运行该文件时,输出不会显示在控制台上,而是会被假脱机到文件中。

JHELLER@orclpdb> @C:\temp\test.sql
JHELLER@orclpdb> quit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
PS C:\> cat C:\temp\dual.txt

D
-
X

PS C:\>
于 2021-01-28T04:59:39.037 回答