Home » Infrastructure » Unix » Urgent : Problem in passing arguments from shell script
Urgent : Problem in passing arguments from shell script [message #113407] Sat, 02 April 2005 07:48 Go to next message
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 Go to previous messageGo to next message
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

Re: Urgent : Problem in passing arguments from shell script [message #113557 is a reply to message #113407] Mon, 04 April 2005 10:52 Go to previous message
Naveen Verma
Messages: 60
Registered: August 2004
Member
Thank you very much William.
I got the point from your example, as I was using $ instead of &.

Thanks
Naveen
Previous Topic: Oracle Listner Hangs After IP Change
Next Topic: Failed database creation HELP!!!
Goto Forum:
  


Current Time: Thu Apr 25 11:24:15 CDT 2024