How can I call a query from a .bat file? (say my query is: select version from system).
Can my .bat file save the output that this query returns? I wanna use this output in my NSIS script.
Overview of SQL Command Line SQL Command Line (SQL*Plus) is a command-line tool for accessing Oracle Database XE. It enables you to enter and run SQL, PL/SQL, and SQL*Plus commands and statements to: Query, insert, and update data.
Take a look at the sqlcmd utility. It allows you to execute SQL from the command line.
For Oracle:
How can I issue a single command from the command line through sql plus?
@echo select version from system; | sqlplus username/password@database
You can either pipe the output to a file and use that, or wrap this in a for
command to parse the output within your batch file.
EDIT: This answer is for SQL Server, not Oracle. (It wasn't immediately clear when the question was posted).
You may want to check the sqlcmd utility.
The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt. The following example executes a query when sqlcmd starts and then exits immediately. Multiple-semicolon-delimited queries can be executed:
sqlcmd -d AdventureWorks -Q "SELECT FirstName, LastName FROM Person.Contact WHERE LastName LIKE 'Whi%';"
To save the output of the query to a file, you can use the -o C:\< filename>
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With