0

I want to use batch script to read a field from oracle Db table. How can I do this? Thanks.

csjoseph
  • 159
  • 2
  • 20

1 Answers1

2

You cant do it in a decent fashion. But can be done by redirectingt he query output to a file, and then read from it. Please see below.

sqlplus -S schema/schema@db @query.sql> __query.tmp
set /p result=<__query.tmp
del __query.tmp

The key is in line 2: "set /p" sets the value of "result" to the value of the first line (only) in "__query.tmp" via the "<" redirection operator.

Courtesy of this thread : Windows batch files: How to set a variable with the result of a command?

EDIT: inside your query file, please add the below lines. And then your query!

set pages 0;
set heading off; 
set feedback off;
Community
  • 1
  • 1
Maheswaran Ravisankar
  • 17,652
  • 6
  • 47
  • 69