Tuesday, January 5, 2010

How to run SQL*Plus one liners on Windows

Suppose you have a simple one line query to run on your Oracle database. Oddly, SQL*Plus doesn't take SQL statements as a command line parameter.

For a simple one liner, it's often too much work to start up sqlplus, logon, type in the SQL statement, then exit. It may also be too trivial to save the SQL statement to a file that you then call from sqlplus, e.g. C:\>sqlplus user/pass @myfile.sql.

To do it all in one line on the command prompt, echo the statement into sqlplus:

echo select count(*) from mytable; | sqlplus user/pass

This technique would probably also work on a Unix box, but I don't have an Oracle db installed on a Unix box to test it out.

1 comment:

Note: Only a member of this blog may post a comment.