1

我的查询基本上是当我尝试从 bash 运行多个 oracle 脚本时,如何在脚本之间添加注释。我尝试通过从双重中选择一个字符串来使用解决方法。但是输出格式不是很好。

谁能给我建议一个更好的方法。

我的代码

#!/bin/bash
#Run Script
    echo "-------------------------------"
    echo "***Running Script1***"
    echo "-------------------------------"
sqlplus -S UID/PSW@DB << EOF
whenever sqlerror exit sql.sqlcode;
set echo off 
set heading off
@/my/path/Script1
Select '--------------' from dual;
select '***Running Script1***' from dual;
Select '--------------' from dual;
@/my/path/Script2
exit;
EOF

输出

-------------------------------
***Running Script1***
-------------------------------
SP2-0310: unable to open file "my/path/Script1.sql"

--------------


***Running Script2***    

--------------

SP2-0310: unable to open file "my/path/Script2.sql"

预期产出

-------------------------------
***Running Script1***
-------------------------------
SP2-0310: unable to open file "my/path/Script1.sql"

--------------
***Running Script2***    
--------------    
SP2-0310: unable to open file "my/path/Script2.sql"
4

3 回答 3

3

尝试使用PROMPTSQL*Plus 的命令:

$ cat tmp.sh
#!/bin/bash

sqlplus -S UID/PSW@DB << EOF
whenever sqlerror exit sql.sqlcode
set echo off
set heading off

prompt =======================
prompt *** Running Script1 ***
prompt =======================
@/my/path/Script1

prompt =======================
prompt *** Running Script2 ***
prompt =======================
@/my/path/Script2

exit
EOF

输出:

$ ./tmp.sh
=======================
*** Running Script1 ***
=======================
SP2-0310: unable to open file "/my/path/Script1.sql"
=======================
*** Running Script2 ***
=======================
SP2-0310: unable to open file "/my/path/Script2.sql"
于 2013-06-27T06:28:40.910 回答
2

怎么样

Select '--------------' || chr(10) || '***Running Script1***' || chr(10) || '--------------' from dual;
于 2013-06-27T06:14:54.247 回答
2

过去,我使用过dbms_output.put_line

dbms_output.put_line('starting process at: '||to_char(sysdate,'HH24:MI:SS'));

这首先需要这一行,以及您最初的“set”语句:

set serveroutput on size 1000000;

如果你在声明/开始/结束块中做一些事情,你可能想要这个:

dbms_output.enable;

这可能会改变你的输出。

于 2013-06-27T06:15:27.447 回答