Passing a unix variable to sql query [message #140037] |
Fri, 30 September 2005 09:42 |
Naveen Verma
Messages: 60 Registered: August 2004
|
Member |
|
|
Hi,
I am writing a function in unix which takes two parameters, say "param1" and "param2". This function consists of a simple sql query, say
function ABC(){
# assuming that connection to oracle went fine
# mentioning only the sql
SELECT * FROM TABLE123
WHERE C_DATE > SYSDATE - $param1
AND C_DATE < SYSDATE - $param2.
}
Can anyone help me out how to get it?
Thanks in advance....
Regards,
N.V
|
|
|
Re: Passing a unix variable to sql query [message #140040 is a reply to message #140037] |
Fri, 30 September 2005 09:59 |
somnath1974
Messages: 15 Registered: July 2005
|
Junior Member |
|
|
Hi Naveen,
Place the sql in a file and invoke the sql file with command line parameters.
If you are using Oracle then you could easily use the command line sequential parameter feature like the &1, &2 etc.
An example:
----------------
sql file : test.sql
SELECT
A.ENAME,
A.ENO,
FROM EMP A,
WHERE E.ENO='&1';
quit;
-----------------
In the shell script invoke this sql file after logging into SQL*Plus client and redirect the output to a file.
sqlplus -S user/pass@sid @get_camps.sql $param1 > my_log.log
Hope this helps !
Best Regards,
Somnath
|
|
|
|
|