How do you pass a value from a shell script into a sqlplus script?

How do you pass a value from a shell script into a sqlplus script?

Post by Mike » Wed, 23 Oct 2002 00:47:48



I gather parameter values in a korn shell script and want to use them in a
sqlplus script that is called from the shell script. How do you pass a value
into the sqlplus script?
 
 
 

How do you pass a value from a shell script into a sqlplus script?

Post by isa » Wed, 23 Oct 2002 01:02:34


Hi:


In the sql:  where field1 = '&1'  and field2 =  '&2'  and field3 = &3

where parameters 1 and 2 are character and the 3 is numeric.

Regards,
                                    Isa



Quote:> I gather parameter values in a korn shell script and want to use them in a
> sqlplus script that is called from the shell script. How do you pass a
value
> into the sqlplus script?


 
 
 

How do you pass a value from a shell script into a sqlplus script?

Post by Alan Mill » Wed, 23 Oct 2002 00:49:41


It's been quite a while (about 5 years) since I've done this but if memory
serves you simply reference command line parameters as &1, &2 ...  from
within SQL*Plus.


Quote:> I gather parameter values in a korn shell script and want to use them in a
> sqlplus script that is called from the shell script. How do you pass a
value
> into the sqlplus script?

 
 
 

How do you pass a value from a shell script into a sqlplus script?

Post by Martin Dohert » Wed, 23 Oct 2002 03:10:46


True, &1 &2 &3 etc. is the way to get the command line parameters into
the sqlplus script, but if your script is anything other than trivial
I'd recommend defining substitution variables with MEANINGFUL names,
copy the parameters into them, and then only use the named variables
throughout your script. Very difficult to work on a long script which is
littered with numeric parameter names.
e.g.
DEFINE P_USER_NAME = "&1"
DEFINE P_START_DATE = "&2"
DEFINE P_DATE_FORMAT = "&3"
...
SELECT *
FROM PN_LEASE_MILESTONES_ALL
WHERE CREATED_BY = '&P_USER_NAME'
AND COMMENCEMENT_DATE = TO_DATE('&P_START_DATE', '&P_DATE_FORMAT')

Those who follow in your footsteps will call upon all known gods to
bless your name for eternity.

Martin


>Hi:


>In the sql:  where field1 = '&1'  and field2 =  '&2'  and field3 = &3

>where parameters 1 and 2 are character and the 3 is numeric.

>Regards,
>                                    Isa



>>I gather parameter values in a korn shell script and want to use them in a
>>sqlplus script that is called from the shell script. How do you pass a

>value

>>into the sqlplus script?

 
 
 

How do you pass a value from a shell script into a sqlplus script?

Post by Joel Gar » Wed, 23 Oct 2002 09:11:20



> I gather parameter values in a korn shell script and want to use them in a
> sqlplus script that is called from the shell script. How do you pass a value
> into the sqlplus script?

schema=$1
password=$2
echo "running my program" >myprog$$.log
date >>myprog$$.log
sqlplus -s <<eof > myprog$$.log 2>&1
$schema/$password
-- Do whatcha want, might hafta escape dollar signs sometimes.
eof

or

echo "Enter year \c"
read year
echo "Enter period \c"
read per

echo "$schema/$password
insert into your_table (year, period, created) values ($year,$per,sysdate);
" | sqlplus  > /dev/null

Or pass parameters the way the other posters do.

jg

see http://www.orafaq.com for other faqqy stuff.

 
 
 

1. How to pass a variable from a shell script to another shell script...

Hi,
         I have written a shell script 1............and internally its
calling another shell script 2........input to  redhat specific
chkconfig command... which executes and builds links in bootstartup
scipt directories (rc.d).

Actually i needs to pass a variable $DIRECTORY  of my command available
( can hard code but i am
setting it in the 1st script) to the 2nd script how to pass that... As
the setting is happening before the calling of
shell script2, i just tried like putting  echo "$DIRECTORY" into the 2nd
shell script, which is not working is there
a way to get the functionality.

shellscript1:
#!/bin/sh
---------
---------
---------
DIRECTORY="/sbin/ntp"
---------
---------
/sbin/chkconfig "shellscript2"
---------

shellscript2:
#!/bin/sh
-------
echo "$DIRECTORY"     <------put to see whether getting the value here
or not..

$DIRECTORY   -c ntp.conf          <------if it is so ,  i could use like
this.................

thanks,
srinivas.

--
office ph: 091-40-3607619

2. control the stdout of printf

3. Passing a variable between shell script and perl script

4. PLEASE HELP! Micron 15FGx & X

5. Passing a variable from a Perl script to a shell script

6. help mid mouse botton

7. Accessing a shell script w/o doing . /script

8. IMAP 4 ???

9. handling SIGINT in shell scripts when executing another shell script.

10. Passing values generated in awk/nawk back to script

11. Q: How can I have a shell script call another shell script...

12. Passing Value to Linux Script from CGI

13. Reading a file and passing it as a value to a script.