In this tutorial, you will learn how to run Oracle SQL Script (SQL*PLUS) from the command line in Windows.
Make sure that the Windows PATH variable already set for the Oracle Database Home, for example, F:\app\Administrator\product\11.2.0\dbhome_1\BIN. Because if the PATH set in the variable, then you would be able to run the SQL*PLUS script from any folder.
Run Oracle SQL*PLUS Script from Command Line in Windows Example
To run the SQL script, follow these steps:
- Open the command prompt by pressing the key Window+R and then type CMD in the Run window and press enter.
- In the Windows command prompt, change the directory where your SQL script exists, for example, CD F:\mysqlscripts and press enter.
- In your scripts folder, type the following command to run the SQL script:
sqlplus username/[email protected] @your_script.sql
To run the script with parameters, for example, you want to pass the employee number 7852 and the employee name SCOTT to the SQL script, below is the example:
sqlplus username/[email protected] @extract_employees_record.sql 7852 SCOTT
If the PATH variable not set for Oracle Home, then you can run the script by providing your Oracle database home path, for example:
F:\app\Administrator\product.2.0\dbhome_1\BIN\sqlplus username/[email protected] @extract_employees_record.sql 7852 SCOTT
If the SQL script is not in the current directory, then you have to give the path for the SQL script too, for example:
F:\app\Administrator\product.2.0\dbhome_1\BIN\sqlplus username/[email protected] @C:\emp_folder\extract_employees_record.sql 7852 SCOTT
In the above case, you can run the SQLPLUS command from any folder, and also can run the SQL script from any folder because you are providing the path.
You can also run the SQL script directly in SQL*PLUS, to do this follow these steps:
- Open SQL*PLUS and connect to the database.
- In the SQL command prompt, type the following command to run the script, for example, you want to run the emp_record.sql script from the C:\myscripts\ folder: