See this code:
test.sh
#!/bin/bash
echo "hello!"
klsdslkdsd
echo "bye"
When I run it I get:
hello!
/tmp/test.sh: line 3: klsdslkdsd command not found
bye
Although there is a syntactic error, the execution goes one (is a script after all).
Now, if I do:
testWithStop.sh
#!/bin/bash
set -e
echo "hello!"
klsdslkdsd
echo "bye"
I get:
hello!
/tmp/test.sh: line 5: klsdslkdsd command not found
The execution stops because I get an exit error from every executed line. If exit != 0 it aborts.
I would like to replicate this behavior in a set of (oracle) PL/SQL (and solely SQL) code.
At this point, even with error, the Oracles DB Manager manages the error gracefully and don't stop the execution of the SQLs. I would like that, when an error (syntactic or semantic) is found, the program aborts but without touching the logic of the program (if so, I would have to change several hundreds of PL/SQL and is not possible).
I know I could do it using raiserror or creating a macro anonymous block that encapsulate portions of my codes, so I could retrieve the exceptions. As I said, it could not be possible to do with several hundreds (could be thousands) of isolated (and logic complex) PL/SQLs
Is there an equivalent to set -e in SQL or an elegant way to do it?
EDIT:
In particular, I´m executing (and calling) de PL/SQLs via a shell script (bash).
For example, the sqlbash.sh file:
#!/bin/bash
sqlplus ..... <<EOF
select * from table;
sdsdsfdsf <--- intentional error!
select * from table2;
EOF
If I called the script, I will get the syntactic error, but the execution goes on and doesn't abort. I would like to abort, for example, mimicking the behavior of an exit 1.
Something like:
#!/bin/bash
sqlplus ..... <<EOF
select * from table;
sdsdsfdsf <--- intentional error!
exit 1 <--- it will abort and the script WILL FAIL at this point
select * from table2;
EOF
I'm working with an scheduler, so, it is necessary for me to see that the script fails, not that it was executed and gave me warnings.