简体   繁体   English

如何在shell脚本中使用oracle $$ PLSQL_LINE?

[英]How to use oracle $$PLSQL_LINE in a shell script?

I want to log the line number of a stand alone block within a shell script. 我想记录一个shell脚本中一个独立块的行号。

I am trying to use the below code but its not working. 我正在尝试使用以下代码,但无法正常工作。 Please let me know if there is a working solution for this. 请让我知道是否有可行的解决方案。

#!/bin/ksh

result=`sqlplus -s $DATABASE <<EOF
SET SET HEAD OFF;
SET PAGES 0;
SET FEEDBACK OFF;
SET SERVEROUTPUT ON SIZE UNLIMITED;
SET DEFINE OFF;

BEGIN
    DBMS_OUTPUT.put_line ('Line number: '|| $$plsql_line);
END;
/
EOF`
echo $result

I get the following error: 我收到以下错误:

PLS-00103: Encountered the symbol "PLSQL_LINE" when expecting one of the following: 
) = - + < / > at in is mod remainder not rem => <an exponent (**)> <>
 or != or ~= >= <= <> and or like like2 like4 likec as between from using 
|| member submultiset The symbol "," was substituted for "PLSQL_LINE" to continue

$需要转义:

DBMS_OUTPUT.put_line ('Line number: '|| \\$\\$plsql_line);

The problem is that the here-document (starting with the first <<EOF ) is expanding shell variables (anything beginning with a $ ). 问题在于,here文档(从第一个<<EOF )正在扩展shell变量(以$开头的任何东西)。 You can suppress that behavior by 您可以通过以下方式抑制该行为

  • putting a backslash before each $ , 在每个$之前$一个反斜杠,
  • or noting that the here document has no useful shell variables, by quoting the first EOF , eg, 或通过引用第一个EOF指出here文档没有有用的shell变量,例如,

    result=`sqlplus -s $DATABASE <<"EOF" result =`sqlplus -s $ DATABASE <<“ EOF”

or 要么

result=`sqlplus -s $DATABASE <<'EOF'

Further reading: 进一步阅读:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM