passing parameters from a shell script to sqlplus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing parameters from a shell script to sqlplus
# 1  
Old 03-09-2005
passing parameters from a shell script to sqlplus

Hi ,
I want to pass parameters from a shell script to a sql script and use the parameter in the sql query ..and then I want to spool a particular select query on to my unix box... for 4 different locations by writing only one sql script
Right now no file is generated on the unix box...it is a solaris box uing korn shell
this is my shell script for reference....

TWO_TASK=$1;export TWO_TASK
TNS_ADMIN=/home/chandrap;export TNS_ADMIN
ORACLE_BASE=/s40/app/oracle;export ORACLE_BASE
ORACLE_HOME=${ORACLE_BASE}/product/9.2.0.3;export ORACLE_HOME
PATH="$ORACLE_HOME/bin:/usr/ccs/bin:/usr/sbin:$PATH";export PATH

date_in_mmddyyyy="`date +\"%m%d%Y%H%M%S\"`"

HPSD_HOME=/home/chandrap/dwh
LOG_DIR=${HPSD_HOME}/logs
DWH_LOG=$LOG_DIR/global_extract${date_in_mmddyyyy}.log

echo $date_in_mmddyyyy > $DWH_LOG
echo ${ORACLE_HOME} >> $DWH_LOG
echo ${TWO_TASK} >> $DWH_LOG

if [ "${TWO_TASK} " = " " ]; then
echo "PARAMETER: Source or Target ORACLE_SID not set; exiting application"
exit
fi

for sitename in Bangalore Niskayuna Shanghai Irvine Munich
do
sqlplus -s hpsddw/hpsddw@$TWO_TASK ${HPSD_HOME}/sql/site_extract.sql $sitename >> $DWH_LOG
echo $sitename
done

grep 'ORA-' $DWH_LOG

if [ $? -eq 0 ]
then
mailx -s "Error in Global extract " $maillist < $DWH_LOG
exit 1
else
mailx -s "Global extract Successful" $maillist < $DWH_LOG
exit 0
fi


and this is my sql script...


spool /projects/hpsd_dwh/global_extract/'&&site_name'||'.csv'


define site_name = &&1


SELECT
'"'||CASE_ID||'","'||
CUSTOMER_SSO_ID||'","'||
CUSTOMER_NAME ||'","'||
CUSTOMER_ORGANIZATION||'","'||
CUSTOMER_SITENAME||'","'||
ENTERED_BY_PERSON||'","'||
ENTERED_BY_PERSON_ORG||'","'||
ASSIGNED_TO_PERSON||'","'||
ASSIGNED_TO_WORKGROUP ||'","'||
ASSIGNED_TO_ORGANIZATION||'","'||
DISPATCH_TO_WORKGROUP||'","'||
ESCALATE_TO_TIER||'","'||
CASE_CATEGORY_PARENT||'","'||
CASE_CATEGORY||'","'||
CLASSIFICATION_PARENT1||'","'||
CLASSIFICATION_PARENT2||'","'||
CLASSIFICATION_PARENT3||'","'||
CLASSIFICATION_PARENT4||'","'||
CLASSIFICATION_PARENT5||'","'||
CLASSIFICATION_PARENT6||'","'||
CLASSIFICATION_PARENT7||'","'||
CLASSIFICATION_PARENT8||'","'||
CONFIG_ITEM_SEARCH_CODE||'","'||
CONFIG_ITEM_CATEGORY||'","'||
CONFIG_ITEM_SUPPLIER||'","'||
TITLE||'","'||
IMPACT||'","'||
STATUS||'","'||
OS||'","'||
MEDIUM ||'","'||
CLOSURE_CODE ||'","'||
IVOC_OFT_NAME||'","'||
DEADLINE||'","'||
ACTUAL_START||'","'||
ACTUAL_FINISH||'","'||
T1_RESPONSETIME||'","'||
T1_T2_ESCALATION||'","'||
T1_HOLDTIME||'","'||
T2_RESP_TIME||'","'||
WAITING_DURATION||'","'||
VENDOR_RESPONSETIME||'","'||
VENDOR_RESOLUTIONTIME||'","'||
ACTUAL_DURATION||'","'||
RE_OPEN_DURATION||'","'||
INBOUND_PHONE_CALLS ||'","'||
STATUS_CALL_BACK ||'","'||
T1_ASSIGNMENT ||'","'||
OUTBOUND_PHONE_CALLS||'","'||
RAL1_POSSIBILITY||'","'||
WAITING_STATUS||'","'||
BUSINESS_UNIT||'","'||
RESOLUTION_TIME||'","'||
RESOLUTION_TIME_VENDOR||'","'||
OVERALL_RAL1_MET||'","'||
SLA_MET||'","'||
SLA_MET_VENDOR||'","'||
ACTUAL_DURATION_SLA||'"'
FROM
HPSDDW_MTD_CASE_DETAILS
where customer_sitename = '&&site_name';

spool off;

exit;



pls get back to me asap...as it is very urgent....

thnks a lot in advance :-)
This User Gave Thanks to phani For This Post:
# 2  
Old 03-09-2005
Quote:
Originally Posted by phani
for sitename in Bangalore Niskayuna Shanghai Irvine Munich
do
sqlplus -s hpsddw/hpsddw@$TWO_TASK ${HPSD_HOME}/sql/site_extract.sql $sitename >> $DWH_LOG
echo $sitename
done
Looks like your problem is with invoking your script.

Code:
for i in Bangalore Niskayuna Shanghai Irvine Munich
do
    sqlplus -s hpsddw/hpsddw @${HPSD_HOME}/sql/site_extract.sql $i<<EOF
    prompt SQLPlus says: $i
EOF
done

Thomas
# 3  
Old 03-13-2005
First time i've replied. Normally loiter.

Phani:
This worked for me when I was doing something similar. Used '.' to terminate variable names.

Hope this helps

Andrew

define Org_Unit = "&1"
define Year_Code = "&2"
define Semesters = "&3"
define Unit_Cd = "&4"
define Unit_Location_Cd = "&5"
define Unit_Class = "&6"
define fileroot = "Q:\ELUP\20030318\"

host "IF NOT exist &fileroot.&Org_Unit. mkdir &fileroot.&Org_Unit."
prompt &fileroot.&Org_Unit.\&Year_Code._&Unit_Cd._&Semesters._&Unit_Location_Cd.&Unit_Class..csv
spool &fileroot.&Org_Unit.\&Year_Code._&Unit_Cd._&Semesters._&Unit_Location_Cd.&Unit_Class..csv

Same with variable values
( CAL_INSTANCE1.CAL_TYPE = 'ACAD-YR' AND CAL_INSTANCE1.ALTERNATE_CODE = '&Year_Code.' )

Last edited by andyl; 03-13-2005 at 08:55 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing a parameter from a shell script to sqlplus

Hi All, I'm new to Linux and scripting, apologies in advance for 'stupid' questions. Please help... Im writing a script that calls a sqlplus script but the sqlplus requires inputs and i cant seem to get this to work. here is my code. #!/bin/sh TERM=vt100 export TERM... (4 Replies)
Discussion started by: Mahomed
4 Replies

2. Shell Programming and Scripting

Shell Script passing parameters to sqlplus code

Hello All, I am interested in finding out a way to pass parameters that are entered at the prompt from HP unix and passed to SQLPlus code with a Shell Script. Is this possible? Thanks (4 Replies)
Discussion started by: compprog11
4 Replies

3. Shell Programming and Scripting

Can't get shell parameters to pass properly to sqlplus

Gurus, The issue I'm having is that my Shell won't accept SQL parameters properly...... Here's they way I'm running it.... applmgr@ga006hds => sh CW_MigrationDeployScript.sh apps <appspwd> <SID> '01-JAN' '31-MAR' The process just hangs not submitting the SQL job... ... (3 Replies)
Discussion started by: WhoDatWhoDer
3 Replies

4. Shell Programming and Scripting

specified path name is too long passing parameters to awk via shell script

Hello, I have this shell script that runs awk code by passing in parameters however now it doesn't work anymore with the parameters and I don't know why. It removes duplicates from an input file based on a part of the last field and a key column. It removes the record with the older datetime... (0 Replies)
Discussion started by: script_op2a
0 Replies

5. Shell Programming and Scripting

Shell Script Passing Parameters For Directory Listing

i have this basic piece of code that i am trying to debug to accept input parameter to be able to display a directory listing of files. cd /u02/app/eatv/dev/out CURDIR=`pwd` echo directory listing of $CURDIR echo if ; then ls -latr else ls -latr $1 fi basically if the script... (9 Replies)
Discussion started by: wtolentino
9 Replies

6. Shell Programming and Scripting

Passing parameters to Shell script for GREP command

I am using grep to capture date from a file . Since i need to use the shell script for different dates ,is it possible to pass the date parameter to the shell script the Script is as below grep -E "08 Aug 2008|2008-08-08"* somefile.txt>test.txt The above script file greps the... (1 Reply)
Discussion started by: sud.tech
1 Replies

7. Shell Programming and Scripting

error in passing a variable to sqlplus from a shell script

hi, I am using a shell script from where i will be conecting to sqlplus.. i am having a problem in passing a variable to sqlplus query.. i will be assigning the variable in the unix environment..whenever i am trying to pass a variable having the contents greater than 2500 characters, i am... (3 Replies)
Discussion started by: kripssmart
3 Replies

8. Shell Programming and Scripting

help me in sending parameters from sqlplus script to unix shell script

Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files.. Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this? Please tell me... (2 Replies)
Discussion started by: Hara
2 Replies

9. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies

10. Shell Programming and Scripting

How to pass Shell variables to sqlplus use them as parameters

Hi, I am trying to pass some of the variables in my shell scripts to the sqlplus call and use them as parameters. For example, I would like to replace the 'SAS', and '20050612' with $var1 and $var2, respectively, how can I do that? --------------------------------------------------------... (1 Reply)
Discussion started by: Jtrinh
1 Replies
Login or Register to Ask a Question