You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Oracle SQL*Plus的spool输出中去除Connection established提示

解决方法
  • 方法1:使用sqlplus静默模式启动(最简便,完全在执行环节过滤)
    你原来启动脚本的命令一般为类似如下格式:
    sqlplus /nolog @check_control.sql
    修改为添加-s(silent)静默参数即可:
    sqlplus -s /nolog @check_control.sql
    静默模式会自动抑制所有sqlplus本身的原生提示信息,包括连接成功的Connection established.、启动时的版本版权横幅、命令执行反馈前缀等,只会输出你主动通过DBMS_OUTPUT打印的内容和查询结果,完全符合需求。

  • 方法2:修改SQL脚本逻辑,连接完成后再开启追加假脱机
    如果不能修改sqlplus启动命令,可以调整你的脚本结构,每次连接完成、参数设置完毕后再开启spool的追加模式,避免连接提示写入文件:

set feedback off
set echo off
set lines 200
set pages 999
-- 先清空原有输出文件
spool check_control_file_record_keep_time.txt;
spool off;

conn /@"HOST1:1521/DB1"
    set echo off
    set feedback off
    set serveroutput on
    -- 连接完成后开启追加假脱机
    spool check_control_file_record_keep_time.txt append;
    DECLARE
        actual_param_setting NUMBER;
     BEGIN
        select value into actual_param_setting from v$parameter where name='control_file_record_keep_time';
        IF actual_param_setting >= 11 THEN
            DBMS_OUTPUT.PUT_LINE('[OK] - DB1 - Parameter control_file_record_keep_time for this database is OK!');
        ELSE
            DBMS_OUTPUT.PUT_LINE('[NOK] - DB1 - Parameter control_file_record_keep_time need to be changed for this database!');
        END IF;
     END;
     /
    -- 执行完毕关闭假脱机,下一次连接的提示就不会写入
    spool off;

conn /@"HOST2:1521/DB2"
    set echo off
    set feedback off
    set serveroutput on
    spool check_control_file_record_keep_time.txt append;
    DECLARE
        actual_param_setting NUMBER;
     BEGIN
        select value into actual_param_setting from v$parameter where name='control_file_record_keep_time';
        IF actual_param_setting >= 11 THEN
            DBMS_OUTPUT.PUT_LINE('[OK] - DB2 - Parameter control_file_record_keep_time for this database is OK!');
        ELSE
            DBMS_OUTPUT.PUT_LINE('[NOK] - DB2 - Parameter control_file_record_keep_time need to be changed for this database!');
        END IF;
     END;
     /
    spool off;

conn /@"HOST3:1521/DB3"
    set echo off
    set feedback off
    set serveroutput on
    spool check_control_file_record_keep_time.txt append;
    DECLARE
        actual_param_setting NUMBER;
     BEGIN
        select value into actual_param_setting from v$parameter where name='control_file_record_keep_time';
        IF actual_param_setting >= 11 THEN
            DBMS_OUTPUT.PUT_LINE('[OK] - DB3 - Parameter control_file_record_keep_time for this database is OK!');
        ELSE
            DBMS_OUTPUT.PUT_LINE('[NOK] - DB3 - Parameter control_file_record_keep_time need to be changed for this database!');
        END IF;
     END;
     /
spool off;
exit
  • 方法3:事后用操作系统命令过滤多余行
    如果前两种方法都不方便使用,可以在脚本执行完成后用系统命令直接过滤掉对应行:
    • Linux/Unix环境执行:
      grep -v "Connection established." check_control_file_record_keep_time.txt > tmp && mv tmp check_control_file_record_keep_time.txt
    • Windows环境执行:
      findstr /v /c:"Connection established." check_control_file_record_keep_time.txt > tmp.txt && move /y tmp.txt check_control_file_record_keep_time.txt

内容的提问来源于stack exchange,提问作者gurbelunder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 00:09:04