【问题标题】:querying v$session table in unix在 unix 中查询 v$session 表
【发布时间】:2014-09-25 10:26:04
【问题描述】:

我正在 unix 中尝试以下操作:

count=sqlplus -s ${DB_USER}/${DB_PASS}@${DB_INST} << END
set echo off head off verify off feed off pages 0 lin 120
select COUNT(USERNAME) from v$session where status not in ('INACTIVE') and osuser not in ('oracle');
exit;
END
echo $count

但它正在评估 $session 为 null 并且只是查询表 "v"。在 unix 中查询此表的任何方式。

【问题讨论】:

  • 你定义了$session变量吗?
  • v$session 是 oracle 中的一个表。
  • 然后这是尝试评估 shell 中的 v$session,以便将其解释为 v + $session 值。您可能必须转义 $ 以便按字面意思对待它。

标签: sql oracle shell unix connection


【解决方案1】:

假设您使用bash,如果您引用您的heredoc 终止字符串(即:&lt;&lt; 'END'),您将阻止$... 的外壳扩展

count=sqlplus -s ${DB_USER}/${DB_PASS}@${DB_INST} << 'END'
set echo off head off verify off feed off pages 0 lin 120
select COUNT(USERNAME) from v$session where status not in ('INACTIVE') and osuser not in ('oracle');
exit;
END
echo $count

来自man bash

here-documents的格式为:

              <<[-]word
                      here-document
              delimiter

如果 word 不被引用,则 here-document 的所有行都经过参数扩展、命令替换和算术扩展,字符序列 \ 被忽略,并且必须使用 \ 来引用字符 \、$ 和 ` .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多