Database Connecion

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

Questions by pranoy

Showing Answers 1 - 16 of 16 Answers

wow_suraj

  • Jun 17th, 2009
 

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
----------------------------------------------

  Was this answer useful?  Yes

NARESH

  • Jul 31st, 2011
 

sqlplus -s username/password@schema name
:wq

  Was this answer useful?  Yes

Ashutosh Gupta

  • Sep 10th, 2011
 

in vi editor
vi connect.sh
#!/bin/bash

sqlplus -s sys as sysdba < startup
spool on;
spool ashu;
connect scott/tiger
select * from emp;
spool off;
exit;
EOF
cat ashu

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions