SnipIT No 4: Run an Oracle SQL script from DOS prompt

SnipIT is a series of short blogs containing useful information in an easily digestible format.
To run an Oracle SQL script file from a DOS prompt (Command Line) you execute sqlplus passing credentials and the database name along with the script to run.

@sqlplus.exe <username>/<password>@<database name> @<script filename>
@sqlplus.exe scott/tiger@testdb @browseUser.sql

Additionally, you can pass values to the script being run.

@sqlplus.exe <username>/<password>@<database name> @<script filename> <value 1> <value 2>
@sqlplus.exe scott/tiger@testdb @browseUser.sql TonyC Engineering

To reference the values passed in the script would look like this:

SELECT * FROM employees WHERE name = '&1' and dept = '&2';





Leave a Reply

Your email address will not be published. Required fields are marked *