Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to update an oracle table using a bat file. Could someone provide the sample code for it? Thanks.
Posted
Comments
PIEBALDconsult 12-Nov-14 15:20pm    
UPDATE? Or ALTER?

1 solution

You can use the SQLPLUS command-line tool to connect to a database, login, and execute a file, but I don't think you can include an SQL statement on the command line.

You can have the BAT file ECHO SQL statements to a file and execute it.

@echo off
@rem Syntax: SQLPLUS.BAT username/password@database "SQL statement" ...

if exist temp.sql del temp.sql

:loop
echo %~2 >> temp.sql
echo ; >> temp.sql
shift /2
if "%~2" neq "" goto loop

echo exit >> temp.sql
sqlplus.exe -S %~1 @temp.sql


Alternatively, writing a console application that will allow that is quite simple.
 
Share this answer
 
v2
Comments
s yu 13-Nov-14 7:53am    
PIEBALD: Thanks for your response. Referring to yours and also the one at http://www.withdata.com/oracmd/batch.html, I created a .bat like that
OraCmd userid=scott/tiger@192.168.1.2:1521:xe sql="truncate table tbl_train2" quit=y
Then I run this bat file, but got the message:
'OraCmd' is not recognized as an internal or external command,
operable program or batch file.
Any advise? Thanks.
PIEBALDconsult 13-Nov-14 8:23am    
Include the path, or set the PATH environment variable.
s yu 13-Nov-14 8:51am    
Using a different approach to implement the SQL statement. Thanks for your help and your response has been credited as Accepted Solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900