如何在 SQLPlus 中进行错误处理,在遇到错误时打印出自定义消息。我把我的代码放在下面。
我的代码
#!/bin/bash
echo "My Scripts run below"
sqlplus -S UID1/UID2@DB1<< EOF
whenever sqlerror exit sql.sqlcode;
@/path/Script1
@/path/Script2
exit;
EOF
echo "My Scripts have run"
输出
My Scripts run below
SP2-0310: unable to open file "/path/Script1.sql"
SP2-0310: unable to open file "/path/Script2.sql"
My Scripts have run
所需输出
My Scripts run below
**Below error in Script1**
SP2-0310: unable to open file "/path/Script1.sql"
**Below error in Script2**
SP2-0310: unable to open file "/path/Script2.sql"
My Scripts have run