Connect to SQLPlus from Shell script [message #347025] |
Wed, 10 September 2008 08:03 |
gokul_ifs
Messages: 41 Registered: March 2006 Location: india
|
Member |
|
|
Hi All,
My requirement is to connect to sqlplus from a linux sell script and execute some SQL queries.
Please share if you have some sample codes for this.
Thanks,
GOKUL
|
|
|
|
|
Re: Connect to SQLPlus from Shell script [message #358303 is a reply to message #347025] |
Mon, 10 November 2008 11:14 |
OracleDBA1
Messages: 7 Registered: November 2008
|
Junior Member |
|
|
hi,
You can easily connect the SQL prompt using the following code:
#/bin/sh
--- some export commands to set the ORACLE_HOME, ORACLE_SID, TNS_ADMIN etc., -------
............
............
VALUE=`sqlplus -s scott/tiger@database_name<<END
spool on
-- or you can also set spool to a location by spool abx.txt
set feedback off
set echo off
set termout off
set trimspool on
select name from v$database;
....
....
....
your SQL code
...
...
end
spool off
END`
(P.S. note the ` char there.)
Save your file as .sh
chmod 777 filname.sh
execute your script.
[Updated on: Mon, 10 November 2008 11:15] Report message to a moderator
|
|
|
|