GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting

 Print  |  
Question:  Database Connecion

Answer: How will you write a shell script to connect to SQL database?


June 06, 2009 05:00:08 #2
 wow_suraj   Member Since: May 2008    Total Comments: 21 

RE: Database Connecion
 

1> #!/bin/ksh

2>

3> sqlplus /nolog < /dev/null

4>

5> connect USER/PASSWORD@DATABASENAME

6>

7> WHENEVER SQLERROR EXIT 5

8> WHENEVER OSERROR EXIT 10

9>

10> @ONE.sql

11>

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

given snippet will connect to the database--line # 3 n 5

and sql script (ONE.sql) will be executed-- line #10


However, other methods are also there to connect to the database

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

sqlplus -s USER/PASSWORD@DATABASE << ENDSQL


sqlplus -S USER/PASSWORD@DATABASE <<-! 2>&1

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

     

 

Back To Question