If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Pass unix variable to sqlplus

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-07, 19:21
queenie680 queenie680 is offline
Registered User
 
Join Date: Apr 2007
Posts: 7
Question Pass unix variable to sqlplus

Hi wrote a unix program that has a parameter startdate and I want to pass the startdate parameter to my sql statement see below:

#!/bin/ksh
homedir=/export/home/pcard
startdate=2
export homedir startdate
EMAIL=blahblah@blah.com
CHARGE_CODE=$homedir/scripts/CHARGE_CODE.txt

unalias rm
cd $homedir/scripts
sqlplus /nolog @$homedir/sql/pcardacl.sql
if [ -s $CHARGE_CODE ]
then
echo "Sucess"
mailx -s "test" $EMAIL < CHARGE_CODE.txt
# rm $CHARGE_CODE
else
echo "Fail"
echo "fail" | mailx -s "fail" blahblah@blah.com
fi

The script above then calls this sql pcardacl.sql script:

@$homedir/sql/connection.sql
Set echo off
Set heading off
Set line 280
SPOOL $homedir/scripts/CHARGE_CODE.txt
select $startdate from dual;
SPOOL OFF
exit

When I run this is does not work. It's not recognizing the $startdate unix variable. I tried using &startdate instead but it asks me to type in something and I don't want that. Sorry I am not too saavy at unix programming and any help would be much appreciated!

Thanks!!!
Reply With Quote
  #2 (permalink)  
Old 04-18-07, 02:30
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
I don't know sqlplus but try this

sqlplus /nolog <<EOF
@$homedir/sql/connection.sql
Set echo off
Set heading off
Set line 280
SPOOL $homedir/scripts/CHARGE_CODE.txt
select $startdate from dual;
SPOOL OFF
exit
EOF
Reply With Quote
  #3 (permalink)  
Old 04-19-07, 17:44
queenie680 queenie680 is offline
Registered User
 
Join Date: Apr 2007
Posts: 7
Thank you so much. It worked!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On