Learner
Learner

Reputation: 21393

Using SQLPLUS command in UNIX scripts

I am trying to understand a simple script that connects to Oracle database using sqlplus command in unix:

1 sqlplus -s /nolog > /dev/null 2>&1 <<EOF
2 whenever sqlerror exit failure
3 connect $user_pwd
4 exit success
5 EOF

If I am using unix then I use commands as sqlplus $user_pwd for connecting to oracle database and to come out of sqlplus command I use exit. Please help me in understanding the lines 1,2,4,5. It may be a simple question for experts but I am not able to understand when to use these.

Upvotes: 1

Views: 4276

Answers (1)

Lajos Veres
Lajos Veres

Reputation: 13725

  • -s is for silent mode (not output anything)
  • > /dev/null 2>&1 things are for force to not display anything. (redirect standard output and standard error to /dev/null)
  • /nolog is for not trying to login with the command line arguments. (the login credentials aren't provided here.)
  • <<EOF is a heredoc input redirect. The lines until EOF will be passed to sqlplus as standard input. (So this is why the last line is EOF)
  • About the whenever line: http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12052.htm So the command's return value will be failure if something wrong happens.
  • connect $user_pwd connects the sqlplus to the server
  • The exit success makes sqlplus returning will success. http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12023.htm#i2697968

Upvotes: 5

Related Questions