1

I have a SQL file that updates certain table. However, the table name depend on the machine name on which the software is installed. (Something like: TableFooBar-MyMachine). I have to write a batch file that calls an Oracle SQL script which will update this table.

So, BatchFile --> Update. Sql --> TableFooBar-MyMachine

The Update. Sql will have statement like:

Update TableFooBar-<Machine-Name> where fooid = -99;

This batch file needs to run on many machines. There are actually many update statements on such tables. I do not want people to edit the sql files. Instead if I set the machine name in the batch file and pass it to the sql, I'm pretty much done! How do I pass the machine name parameter to the .sql file to achieve this?

2 Answers 2

6

you can use substitution variables

update.sql

--
Update TableFooBar-&1 set column_foo='bar' where fooid = -99;
--

and then call

sqlplus foo/bar@db @update.sql <Machine-Name>
Sign up to request clarification or add additional context in comments.

3 Comments

+1, was going to say the same. However, you left off the parameter on the sqlplus call: sqlplus foo/bar@db @update.sql <machine_name>
@DCookie: <Machine-Name> - is the call Parameter :)
Oopps, didn't see it for some reason. Formatting helped :-)
2

Yes, you can do this, by creating the SQL file from the BATCH file.

It would look like this:

@echo off
set SQL = update.sql
ECHO connect username/password@database
ECHO Prompt Updating tables > %SQL%
ECHO Update TableFooBar-%1 where fooid = -99; >> %SQL%

sqlplus @update.sql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.