I want to use batch script to read a field from oracle Db table. How can I do this? Thanks.
            Asked
            
        
        
            Active
            
        
            Viewed 1,571 times
        
    0
            
            
        - 
                    1What exactly you have in mind? – Nick Krasnov Dec 24 '13 at 12:16
- 
                    sorry, batch file means, you want to automate select query and download into a file, is it unix? – Maheswaran Ravisankar Dec 24 '13 at 12:22
- 
                    I firstly add some data to DB and then I take count of rows which already inserted to DB. I want to take this number with batch script and assign to a variable in batch script side. – csjoseph Dec 24 '13 at 12:24
- 
                    No, not unix. System is windows – csjoseph Dec 24 '13 at 12:25
1 Answers
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
- 
                    result comes as COUNT(*) ---------- 2015 I want to take just 2015 number not with field name. – csjoseph Dec 24 '13 at 13:08
- 
                    inside your query file, please add the below lines. Abd then your query! `set pages 0; set heading off; set feedback off;` – Maheswaran Ravisankar Dec 24 '13 at 13:30
- 
                    
