How do I pass arguments to a PL/SQL script on command line with SQLPLUS?

Firstly, you will need to invoke your script like so:

sqlplus.exe MYUSER/mypassword@HOST030 @refreshDataOnOracle.sql foo bar  

Instead of the OS redirection you will use the “@” symbol to indicate the file name to execute. You will also supply the script parameters on the command line. In the script you will refer to the parameters using &1, &2 etc.

update mytable set mycol="&2" where myid = '&1';

which will translate into

update mytable set mycol="bar" where myid = 'foo';

Leave a Comment