How can I issue a single command from the command line through sql plus?

JosephStyons picture JosephStyons · Mar 12, 2009 · Viewed 139.2k times · Source

Using SQL Plus, you can run a script with the "@" operator from the command line, as in:

c:\>sqlplus username/password@databasename @"c:\my_script.sql"

But is it possible to just run a single command with a similar syntax, without a whole separate script file? As in:

c:\>sqlplus username/password@databasename @execute some_procedure

I am interested in this because I want to write a batch file that simply executes a command, without generating a bunch of two-line ".sql" files.

Answer

Patrick Cuff picture Patrick Cuff · Mar 12, 2009

I'm able to run an SQL query by piping it to SQL*Plus:

@echo select count(*) from table; | sqlplus username/password@database

Give

@echo execute some_procedure | sqlplus username/password@databasename

a try.