Home » SQL & PL/SQL » SQL & PL/SQL » retreiving result from sqlplus into batch variable
retreiving result from sqlplus into batch variable [message #8067] Thu, 24 July 2003 09:55 Go to next message
smilo
Messages: 2
Registered: July 2003
Junior Member
I want to issue sqlplus command from my DOS or UNIX shell and, assuming that returning value is a single value, to capture it in script variable for futher use (to display or use in further process). I.e. I want to fetch a file name from some table, then use that name to open file in batch program.

How should my sql script look like, and how my DOS/UNIX one? Any ideas?
Re: retreiving result from sqlplus into batch variable [message #8087 is a reply to message #8067] Fri, 25 July 2003 05:03 Go to previous messageGo to next message
Thomas G
Messages: 58
Registered: April 2003
Member
In Unix it could be done with backticks.

You have to make shure the SQL returns JUST the value when started (No table header, no "connected to" messages. An example would be :

-----
#!/bin/bash

TEST =`sqlplus -s user/password@database <<!
set FEEDBACK OFF
set HEADING OFF
set PAGES 0
set TAB off

select value
from table
where thingie = something;
!`

echo $TEST
-----

But in DOS(Windows) that obviously doesn't work. ;-)

If you look for a solution that works under Unix and DOS without any modifikation to the scripts I would have a look at PERL.
Re: retreiving result from sqlplus into batch variable [message #8092 is a reply to message #8087] Fri, 25 July 2003 12:16 Go to previous messageGo to next message
smilo
Messages: 2
Registered: July 2003
Junior Member
Thanks, I'll try that.
Re: retreiving result from sqlplus into batch variable [message #12681 is a reply to message #8087] Tue, 01 June 2004 01:59 Go to previous message
satish
Messages: 112
Registered: September 2000
Senior Member
#!/bin/bash

TEST =`sqlplus -s user/password@database <set FEEDBACK OFF
set HEADING OFF
set PAGES 0
set TAB off

select value
from table
where thingie = something;
!`

echo $TEST

while executing it in dos i am getting problem.
how to get a value from sqlplus to dos batch variable
Previous Topic: Depending objects
Next Topic: SQL session error
Goto Forum:
  


Current Time: Thu Apr 25 11:57:39 CDT 2024