Urgent : Problem in passing arguments from shell script [message #113407] |
Sat, 02 April 2005 07:48 |
Naveen Verma
Messages: 60 Registered: August 2004
|
Member |
|
|
Hi,
I am writing a shell script, in that I have to take 4 command line arguments. I need to use these arguments in a sql query.I am getting problem in doing this as stated below.
In my main shell script I am exporting all the argument variables, then I tried in two ways.
1.connect to the oracle using sqlplus, then call a sql file where I write all the oracle code by using those exported variables.
2.call another shell script where I connect to oracle using sqlplus, then I write all the oracle code by using those exported variables.
But in two cases I got some error message that the exported variables are not declared.
Could you Please help me to come out this problem asap as I need to fix it immediately.
Thanks
Naveen
|
|
|
Re: Urgent : Problem in passing arguments from shell script [message #113410 is a reply to message #113407] |
Sat, 02 April 2005 09:43 |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
I don't see where exporting variables comes into it. Perhaps if you posted your code and the error message, I could see what you're doing wrong.
Put the SQL into a .sql command file like this:
testscript.sql:set linesize 100 pagesize 999 trimspool off pause off echo off
SELECT * FROM emp
WHERE job = UPPER('&1')
AND deptno = &2;
Then call it from a shell script like this:
testscript:#!/bin/ksh
sqlplus /nolog <<-endsql
connect scott/tiger@dev
@testscript $1 $2
exit
endsql
Then make testscript executable:
chmod +x testscript
and run it:
/Users/williamr: testscript clerk 10
SQL*Plus: Release 9.2.0.1.0 - Developer's Release on Sat Apr 2 15:37:28 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> Connected.
SQL>
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- --------- ---------- --------- ---------- ---------- ----------
7934 MILLER CLERK 7782 23-JAN-82 1300 10
1 row selected.
SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Developer's Release
With the Partitioning and Oracle Data Mining options
You could do this all in one script, but I'm against SQL in shell scripts.
[Updated on: Sat, 02 April 2005 09:45] Report message to a moderator
|
|
|
|