CodeNewbie Community 🌱

Cover image for Run Oracle SQL Script From Command Line in Windows
Hassan Abd Elrahman
Hassan Abd Elrahman

Posted on • Originally published at oraask.com

Run Oracle SQL Script From Command Line in Windows

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

:\MyScript\ScriptWithoutParameter.sql

This Article created initially on Oraask.com

Top comments (0)