Link to home
Start Free TrialLog in
Avatar of GeekMan
GeekMan

asked on

Looking for "integrating sqlplus/ksh" resources

Can someone direct me to some good resources that have examples of integrating sqlplus execution inside a Korn Shell script.
I need to:
- Pass sqlplus success/fail status back to the ksh.
- Trap sql errors in my ksh application and perform "ksh" conditional logic on these errors.
- Toggle back and forth between ksh execution and sqlplus.
- Run and capture stored procedure results (hopefully same as std SQL query).

I'm a Windows programmer by trade so much of this is "Greek" to me.

Operating system is (I believe...)HP-UX V.5.1 1885 alpha
DB is Oracle 8i

Thanks for your help.
Avatar of ellesd
ellesd

If you are running sqlplus from the script, you will need to test the $? variable for success or failure (0 is success and non-zero is failure:

if [ "$?" -eq 0 ]
then
  SUCCESS CODE
else
  FAILURE CODE
fi

You need a space after the [ and before the ].

If you are trying to execute certain code based on certain errors returned, you will put a case statement in the FAILURE CODE section:

case $?
in
  1)
     cmd1
     cmd2
     ;;
  2)
     cmd3
     cmd4
     ;;
  *)
     default code
     ;;
esac

Obviously you put your desired error codes in place of the 1, 2, and so on (list as many as you are checking).  Replace the cmd1, cmd2, ... with your desired commands.
The two semicolons are required to end execution of that particular set of commands.  The *) case is to catch any value you did not account for and run whatever commands you want for that situation.

Elaborate on the rest and I should be able to assist some more.
ASKER CERTIFIED SOLUTION
Avatar of ellesd
ellesd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GeekMan

ASKER

Thanks for your help