How to write batch file for sqlplus

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Indra Rai
Posts: 3
Joined: 27 May 2014 04:27

How to write batch file for sqlplus

#1 Post by Indra Rai » 27 May 2014 04:33

Dear All,

I have to create a batch file containing following syntax. How can I create batch file. Please help.

sqlplus / as sysdba;
sql> update
sql> MyTable
sql> SET MyColumn ='Y'
sql> WHERE MyColumn ='N';
sql> COMMIT;

Indra Rai
Posts: 3
Joined: 27 May 2014 04:27

How to write batch file for sqlplus

#2 Post by Indra Rai » 27 May 2014 04:50

Dear All,

I have tried to make dos batch file for sqlplus program.

sqlplus / as sysdba;
update
UPDATE
MyTable
SET MyColumn ='Y'
WHERE MyColumn ='N';
COMMIT;


But, when I run bath file only sql prompt will appear (SQL>) rest of the command will not functionning..

einstein1969
Expert
Posts: 976
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: How to write batch file for sqlplus

#3 Post by einstein1969 » 27 May 2014 07:24

hi Indra,

you can save the sql commands in a file. For example in update.sql write...

update.sql:

Code: Select all

UPDATE MyTable SET MyColumn ='Y' WHERE MyColumn ='N';
COMMIT;


then in a batch file update.cmd, you can start the sql commands file.
update.cmd:

Code: Select all

sqlplus / as sysdba @update.sql


einstein1969

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How to write batch file for sqlplus

#4 Post by Aacini » 27 May 2014 10:37

You may create a TEXT file with these lines (for example UPDATE.TXT):

Code: Select all

sqlplus / as sysdba;
update
UPDATE
MyTable
SET MyColumn ='Y'
WHERE MyColumn ='N';
COMMIT;
exit

... and then "execute it" this way: CMD < UPDATE.TXT

Antonio

Indra Rai
Posts: 3
Joined: 27 May 2014 04:27

Re: How to write batch file for sqlplus

#5 Post by Indra Rai » 28 May 2014 03:22

Thank you very much both of you. It works.

Post Reply