views:

897

answers:

2

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.

A: 

Have you tried something like this?

sqlplus username/password@database < "EXECUTE some_proc /"

Seems like in UNIX you can do:

sqlplus username/password@database <<EOF
EXECUTE some_proc;
EXIT;
EOF

But I'm not sure what the windows equivalent of that would be.

Eric Petroelje
Note, on unix ( and probably windows ), you really shouldn't ever the username/password syntax, that will expose your password to every user on the system. Use external auth if you need to.
Matthew Watson
The < symbol is a pipe in Windows too. Nice idea, but it does not work.
JosephStyons
that command line will be visible to other os users with (e.g.) `ps -ef`, if you have to include username and password, better to execute "sqlplus /nolog <<EOF" and have the first line be "connect username/password". Not the ideal solution, but it's better in that at least it doesn't expose the clear text username and password in output from `ps -ef`
spencer7593
+2  A: 

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.

Patrick Cuff
Works great. Thanks!
JosephStyons