Run Oracle SQL Script From Command Line in Windows
Sometimes we have to run a particular SQL script from the Windows command line “CMD” with or without parameters. Here are the steps required to perform this task.
Join the DZone community and get the full member experience.Join For Free
Sometimes we need to run a particular SQL script from the Windows command line “CMD” with or without parameters.
This article will guide you through the steps required to perform this task to get an employee’s information — both with and without parameters.
To Run SQL Scripts from Windows Command Line CMD
- Press Windows + R from your keyboard, then type cmd and press enter.
- Change the current directory to the directory where your script is available.
- To run SQL Script without parameters, we need to type this command.
sqlplus hr/hr @ScriptWithoutParameter.sql
- To run SQL Script with parameters, we need to type this command.
sqlplus hr/hr @ScriptWithoutParameter.sql 101
It is important that when running SQL script with parameters from CMD:
- In our script, the WHERE condition should be typed in the substitution variable as follows
select * from EMPLOYEES where employee_id = &1;
- For the script above, we passed &1 to be replaced with 101 to bring employee number 101's data.
To Run SQL Script from SQL PLUS
- Open SQL PLUS and then connect to the database.
- In SQL Command, type the following command and press enter
Published at DZone with permission of Hassan Abd Elrahman. See the original article here.
Opinions expressed by DZone contributors are their own.