I am very new to DOS programming but have been doing Unix for a while.
This may sound a very basic problem to the experts, so please excuse my naivity.
Heres the problem -
Say I have 500 files in a folder with their file names in 1-12345-12345678 format. I got to read each file names to a single variable and pass it on to a pl/sql script. The pl/sql script will then update a table on sql server based on this variable (one of the columns of the table is a primary key based on this file name).
My questions are -
1. How do i read each file name to a variable in my batch script and then run it into a loop for as many files as present. (basically executing the pl/sql script as many times as there are number of files).
2. How do i pass the variable to the call for executing the pl/sql script from my batch script.
I appreciate your time and inputs on this and Thanks in advance for any response.
Thanks,
Sanders.
How do you read a filename and substring it to variables
Moderator: DosItHelp
-
- Posts: 3
- Joined: 05 Oct 2011 11:33
Re: How do you read a filename and substring it to variables
Um, pl/sql sounds like Oracle. Are you sure you could use Windows Batch in this environment?
Regards
aGerman
Regards
aGerman
Re: How do you read a filename and substring it to variables
Sure aGerman - sqlplus is a command line utility that works great in Windows Batch.
Sanders - There are many variations for reading file names from a directory into variables, almost always using some form of the FOR command.
Here is the simplest form:
The asterisk wild card is expanded to all file names in the current working directory using the FOR loop, with one name per pass in the %%F variable. (Note - the % is doubled up for %%F only within a script. If executed directly from the command line then you would only use a single percent before the F).
Presumably your sql script will have an EXIT or QUIT command so that it terminates, thus enabling the FOR loop to go on to the next iteration.
From an interactive command prompt you can enter HELP FOR to get help on the many variations and options available to the FOR command.
Dave Benham
Sanders - There are many variations for reading file names from a directory into variables, almost always using some form of the FOR command.
Here is the simplest form:
Code: Select all
for %%F in (*) do sqlplus userName/password@instance @script.sql %%F
The asterisk wild card is expanded to all file names in the current working directory using the FOR loop, with one name per pass in the %%F variable. (Note - the % is doubled up for %%F only within a script. If executed directly from the command line then you would only use a single percent before the F).
Presumably your sql script will have an EXIT or QUIT command so that it terminates, thus enabling the FOR loop to go on to the next iteration.
From an interactive command prompt you can enter HELP FOR to get help on the many variations and options available to the FOR command.
Dave Benham