JL Computer Consultancy

Setting the Oracle SID (on Unix)

September 1999

Everyone who uses Oracle on a Unix box has probably written a little wrapper to stick around the oraenv command to help them set and Oracle SID and sundry extra related environment variables. This is my version which I call automatically at the end of the .profile script - it simply displays all the Oracle SIDs in the oratab file (which I assume is in /var/opt/oracle rather than /etc), picks the first one as default, and then leaves to press return, or type a different SID.

The script:
echo ""
echo "Available (oratab) SIDS"
echo "-----------------------"
echo ""
grep "^[^#]" /var/opt/oracle/oratab | \
               awk -F: '{printf("\t%-6s\t%-30s\n",$1,$2)}'
echo ""
echo "Select a SID"
echo ""
ORACLE_SID=`grep "^[^#]" /var/opt/oracle/oratab | \
               awk -F: '{printf("%s\n",$1)}' | head -1`
. oraenv
#       SHLIB for oracle 8 in particular
export DISPLAY=`hostname`:0
cd $ORACLE_HOME/../..
export ORACLE_BASE=`pwd`
cd -

Sample of the output:

Available (oratab) SIDS
        D734    /u05/app/oracle/product/7.3.4 
        D815    /u00/app/oracle/product/8.1.5 
Select a SID
ORACLE_SID = [D734] ? 

Back to Main Index of Topics