1

My query basically is when I am trying to run multiple oracle scripts from bash how do I put comments in between the scripts. I have tried using a workaround by selecting a string from dual. But the output formatting isn't very good.

Can anyone please suggest me a better way.

My Code

#!/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

Output

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

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


***Running Script2***    

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

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

Expected Output

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

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

3 Answers 3

3

Try using the PROMPT command of SQL*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

Output:

$ ./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"
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant . Exactly what I was looking for.
2

In the past, I've used dbms_output.put_line :

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

This requires this line first, with your initial "set" statements:

set serveroutput on size 1000000;

And if you're doing stuff in a declare / begin / end block, you might want this:

dbms_output.enable;

Which may change your output.

Comments

2

How about

Select '--------------' || chr(10) || '***Running Script1***' || chr(10) || '--------------' from dual;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.