Oracle SQL: How to use sqlplus without Oracle binaries or using oracle instant client libraries
Once Oracle DB is installed , Normally sqlplus is part of the oracle DB bin path. From the path use ./sqlplus to connect .
In some cases , where DB is not available in the system and still we need to connect to DB. In that case, oracle provides a workaround to connect to the DB.
Download the client from oracle site - Below is the Sample download link given for linux X86 32 bit.
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html?printOnly=1
instantclient-sqlplus-linux-12.2.0.1.0.zip
Similarly downloads are available for different OS ,chip architectures and DB versions.
Once downloaded, unzip it to a path like "/sw/instantclient_12_2"
Add this path to the PATH and LD_LIBRARY_PATH environment variables.
export PATH=$PATH:/sw/instantclient_12_2
export LD_LIBRARY_PATH=/sw/instantclient_12_2
Below is the sample shell script to connect to the DB using the sqlplus client
#!/bin/bash
export PATH=$PATH:/sw/instantclient_12_2
export LD_LIBRARY_PATH=/sw/instantclient_12_2
connectstring='DB_USER/DB_Password@(description=(address_list=(address=(protocol=TCP)(host=DB_hostname)(port=DB_portnumber)))(connect_data=(service_name=DB_servicename)))'
query=`echo -e "SELECT date from dual;"`
echo $query
sqlplus -S ${connectstring}<< EOF
$query
exit;
EOF
In some cases , where DB is not available in the system and still we need to connect to DB. In that case, oracle provides a workaround to connect to the DB.
Download the client from oracle site - Below is the Sample download link given for linux X86 32 bit.
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html?printOnly=1
instantclient-sqlplus-linux-12.2.0.1.0.zip
Similarly downloads are available for different OS ,chip architectures and DB versions.
Once downloaded, unzip it to a path like "/sw/instantclient_12_2"
Add this path to the PATH and LD_LIBRARY_PATH environment variables.
export PATH=$PATH:/sw/instantclient_12_2
export LD_LIBRARY_PATH=/sw/instantclient_12_2
Below is the sample shell script to connect to the DB using the sqlplus client
#!/bin/bash
export PATH=$PATH:/sw/instantclient_12_2
export LD_LIBRARY_PATH=/sw/instantclient_12_2
connectstring='DB_USER/DB_Password@(description=(address_list=(address=(protocol=TCP)(host=DB_hostname)(port=DB_portnumber)))(connect_data=(service_name=DB_servicename)))'
query=`echo -e "SELECT date from dual;"`
echo $query
sqlplus -S ${connectstring}<< EOF
$query
exit;
EOF
Hope it help someone !!!!!
Comments
Post a Comment