<p>I just want ask the steps when trying to create a simple SQL select statement in UNIX inside/within IF..THEN..FI statement.</p>

<p>I know how to use the 'select' and 'if..then' statements in SQL*Plus, but I'm having a difficulties having a UNIX script to point to variables: If 'ABC' to 'Select...'</p>

<h2>Example:</h2>

<p>if [ "$?" = 'ABC' ]
then
    SELECT employid, name, age FROM tablename;
else
    exit 1
fi</p>

<p>if [ "$?" = 'XYZ' ]
then
    SELECT employid, name, age FROM tablename;
else
    exit 1
fi</p>

<p>How do I put it in a UNIX script more correctly syntax wise and right to the point?</p>

<p>Thanks.</p>

This sounds like you're trying to embed SQLPlus in a shell script.  From memory the incantation should look something like:
```
```
if [ $? -eq ABC ]; then
SQLPLUS /S USER/PASS@Instance <<EOF
SET echo off;
SET pagesize 0;
SET heading off;
SPOOL foo.out
select foo from bar
EOF
fi
```
```
Everything between the SQLPLUS and EOF is passed to SQLPlus, so we have some statements to control the formatting (you may want different ones) and the actual query.  The SPOOL command in the SQLPlus script sends the output to a file.  For more detailed docs on using SQLPlus, You can download them from
Oracle's web site.