dazedandconfused
dazedandconfused

Reputation: 85

Getting oracle sqlplus select count value into dos batch file

I've got a DOS batch file running an SQLplus select to get a count of rows where a particular column value is 10. This is working fine and I've sucessfully output the value to a file however I'm now having real problems using that value in the batch file. The problem seems to be due to it being a right justified 10 character string.

so if my value is 0 i get this,

         0

or if my value is 7000 I would get this,

      7000

What I really want is this,

0

or this

7000

Im reasonably sure that If I had the data starting in column 1 then I could use the following to read the data,

for %%a in ("C:\Program Files (x86)\BBWin\ext\status10.LST") do if /I %%a GTR 300 echo %%a >> "C:\Program Files (x86)\BBWin\ext\status10.txt"

Upvotes: 0

Views: 1499

Answers (2)

dbenham
dbenham

Reputation: 130879

The galuano1 answer certainly strips spaces from a value, it should not be required in your case.

The default token delimiters for FOR /F are space and tab. So the leading spaces will be trimmed for you. The value does not have to be left justified :-)

You need to use FOR /F with the USEBACKQ option to read a file with spaces in the name.

for /f "usebackq" %%a in ("C:\Program Files (x86)\BBWin\ext\status10.LST") do ...

But you don't even need a file! You can directly process the results of your sqlplus using FOR /F by enclosing the command in single quotes.

for /f %%a in ('sqlplus ...') do ...

You should carefully read the help documentation for the FOR command: type HELP FOR or FOR /? from the command line. There are many subtle differences in how FOR can be used.

You might also check out this excellent FOR loop tutorial

Upvotes: 1

Pradeep Pati
Pradeep Pati

Reputation: 5919

You can remove the spaces by doing the following

set str=%str: =%
echo."%str%"

Where str is the variable containing the value with spaces.

More info here

Upvotes: 0

Related Questions