【问题标题】:how to get SQL query output from sqlplus to bash script如何从 sqlplus 获取 SQL 查询输出到 bash 脚本
【发布时间】:2020-08-29 13:36:42
【问题描述】:

如何使用sqlplus作为中间人执行sql查询或脚本并将输出插入bash变量?

【问题讨论】:

    标签: sql bash oracle oracle11g sqlplus


    【解决方案1】:

    (至少)3 个好看的 stack-overflow 和其他网站教程对我没有任何帮助,所以我发布了对我有用的内容,希望它对其他人有用。

    代码:

    #!/bin/bash
    export ORACLE_SID=<DB_SID>
    VAL=""
    VAL=`sqlplus -s / as sysdba << EOF
    whenever sqlerror exit sql.sqlcode;
    set echo off
    set heading off
    @<sql_script_path>
    exit;
    EOF`
    echo $VAL 
    

    【讨论】:

      猜你喜欢
      • 2017-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多