【问题标题】:Calling two functions one after other is failing in bash/sqlplus一个接一个地调用两个函数在 bash/sqlplus 中失败
【发布时间】:2013-02-08 19:45:51
【问题描述】:

我有两个函数——ABC、XYZ。 ABC 删除 table1 中的一些行作为 user1,XYZ 删除一些用户作为 DB 用户。首先我打电话给ABC,然后是XYZ。 ABC 函数正在执行,但在 XYZ 处失败 - “XYZ:找不到命令”

function ABC
{
        sqlplus -s $ur1/$pwd@$SID << EOF

        delete from table1 where row_name = 'A1';
        delete from table2 where row_name = 'A2';
        exit

        EOF
}

function XYZ
{
 sqlplus eip_dba/eip_dba$result@${input} << eof
 set timing off
 set serveroutput on size 10000
 set feedback off
 spool xyz_$input.out

 drop user usr1 cascade;
 drop user usr2 cascade;
 drop user usr3 cascade;
 commit;
 exit
 eof
}

ABC
XYZ

bash-3.2$ ./db_test.sh 

2 rows deleted.


2 rows deleted.

./db_test.sh: line 100: XYZ: command not found

请告诉我出了什么问题。

提前致谢。

【问题讨论】:

  • 谢谢。从现在开始,我会使用这个技巧。

标签: linux oracle bash sqlplus


【解决方案1】:

尝试删除 EOF 之前的空格

function ABC
{
        sqlplus -s $ur1/$pwd@$SID << EOF

        delete from table1 where row_name = 'A1';
        delete from table2 where row_name = 'A2';
        exit

EOF
}

我在一个示例程序中进行了尝试,它解决了问题。

【讨论】:

    【解决方案2】:

    here-documents的格式为:

        <<WORD
    here-document content ...
        here-document content ...
      here-document content ...
    WORD
    

    WORD 可以是任何你喜欢的标签,但结束标记必须是行中唯一的东西,前后不能有空格。

    在您使用eofEOF 作为标签的示例函数中,您应该删除它们前面的空格字符,以便它们真正位于行首,如下所示:

    function ABC
    {
            sqlplus -s $ur1/$pwd@$SID << EOF
    
            delete from table1 where row_name = 'A1';
            delete from table2 where row_name = 'A2';
            exit
    
    EOF
    }
    
    function XYZ
    {
     sqlplus eip_dba/eip_dba$result@${input} << eof
     set timing off
     # ... and so on ....
    
    eof
    }
    

    也就是说,结尾 EOFeof 正好在行首,也没有尾随空格。

    【讨论】:

    • 谁能告诉我如何在stackoverflow的“添加评论”区域插入代码?每次我开始一个新线程。相反,我希望有一个线程,其中包含一些关于同一脚本的其他问题。
    猜你喜欢
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 2021-04-22
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多