Take the 2-minute tour ×

Is it possible to do something like this?

$ sqlplus -s user/pass "select 1 from dual" or
$ echo "select 1 from dual" | sqlplus -s user/pass

I know I can put select 1 from dual in a file and do this:
$ sqlplus -s user/pass @myFile.sql

but I'm wondering if it's actually necessary to create a file just to satisfy sqlplus

share|improve this question
add comment

4 Answers

up vote 19 down vote accepted

Just be aware that on Unix/Linux your username/password can be seen by anyone that can run "ps -ef" command if you place it directly on the command line . Could be a big security issue (or turn into a big security issue).


sqlplus -s /nolog <<EOF
connect user/pass
select blah;
share|improve this answer
+1 for security angle... –  DCookie Oct 28 '09 at 21:24
not always true, depending on Oracle version and OS, but probably a good standard to follow –  dpbradley Oct 29 '09 at 13:02
add comment

I'm able to execute your exact query by just making sure there is a semicolon at the end of my select statement. (Output is actual, connection params removed.)

echo "select 1 from dual;" | sqlplus -s username/password@host:1521/service



Not that is should matter but sqlplus is running on Mac OS X Snow Leopard and the server is Oracle 11g.

share|improve this answer
+1, but be aware that if you're doing anything moderately complicated in SQL*Plus you'll usually be making a few SET directives and this will get messy if you're looking to have a one-line command. –  dpbradley Oct 28 '09 at 20:22
add comment

I assume this is *nix?

Use "here document":

sqlplus -s user/pass <<+EOF
select 1 from dual;

EDIT: I should have tried your second example. It works, too (even in Windows, sans ticks):

$ echo 'select 1 from dual;'|sqlplus -s user/pw


share|improve this answer
add comment

My version

sqlplus -s username/password@host:port <<< "query"
share|improve this answer
add comment

Your Answer


