Wednesday, January 20, 2016

unix script to connect oracle DB

Connect_db_oracle_unix.sh
#This Next line contains the name of a file, if you want to save all data #outside.
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/client_1;
export ORACLE_BASE=/u01/app/oracle;
export ORACLE_SID=ORCL;//your db sid value

PATH=$PATH\:/u01/app/oracle/product/12.1.0/client_1/bin ; export PATH;

file="outputfile.txt"
sqlplus -s usrnm/pwd<< EOF
set linesize 10000
set head off
SET COLSEP "|"

spool $file

SELECT * from users where rownum<5;

spool off

No comments:

Post a Comment