Tuesday, April 13, 2010

Connection To Oracle Through Shell Script

Oracle environment variables; if not all then set at least the last two of the following:




export ORACLE_BASE=/path/to/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11g
export ORACLE_TERM=xsun
export NLS_LANG=American_America.US7ASCII
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export ORACLE_PATH=$ORACLE_HOME/bin
export PATH=$ORACLE_HOME/bin:$PATH
Set the Path of Oracle SID


export ORACLE_SID=orcl (Optional).For More Information(http://www.orafaq.com/wiki/ORACLE_SID)



However, if you have a Service Name instead and your oracle instance runs off of a different port than the default, then use the following format for connecting.



sqlplus -s LOGIN/PASSSWD@SERVERNAME:ORA_PORT/SERVICE_NAME

sqlplus -s LOGIN/PASSSWD  (With out Service Name and with default port)

Ex:--



#!/bin/sh -e 


export ORACLE_BASE=/path/to/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11g
export ORACLE_TERM=xsun
export NLS_LANG=American_America.US7ASCII
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export ORACLE_PATH=$ORACLE_HOME/bin
export PATH=$ORACLE_HOME/bin:$PATH


sqlplus -s LOGIN/PASSSWD@SERVERNAME:ORA_PORT/SERVICE_NAME << EOF > sqloutput

set pagesize 0;
select * from blah;
update blah;
commit;
exit;

No comments:

Post a Comment