How to Execute SQL Statements in One CMD Line

  • by
If your query contains just only one statement, you can do this:
C:Usersed>echo select name from v$database; | sqlplus scott/tiger@orcl
When the query is finished, the command will exit sqlplus automatically.

If your query contains several statements in a file, you can execute it (e.g. run_check.sql) like the following commands:

Method 1: The syntax is supported by sqlplus.
C:Usersed>sqlplus sys/password@primdb_scan as sysdba @run_check.sql
By this method, you have to add "exit" in your SQL script to make itself leave sqlplus.

Method 2:
C:Usersed>sqlplus scott/tiger@orcl < run_check.sql
This will exit sqlplus automatically.

Method 3:
C:Usersed>echo @run_check.sql | sqlplus scott/tiger@orcl
This will exit sqlplus automatically.

Leave a Reply

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