I'd like to开发者_StackOverflow社区 run a sqlplus script from a cron job.
I thought I could put a line like:
CONNECT "myuser/mypass@mydb"
within the script and then just execute it with:
sqlplus @myscript
However, when I do so, I get:
SP2-0306: Invalid Option
SP3-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
Am I misunderstanding the usage of the connect command?
When running CONNECT
inside SQL*Plus
, remove the quotes:
CONNECT myuser/mypass@mydb
They double quotes are required if you are passing the credentials as an argument to sqlplus
:
sqlplus "myuser/mypass@mydb"
, for the shell to parse myuser/mypass@mydb
as a single argument if you have spaces in your connection identifier or use additional options like AS SYSDBA
.
Use the /NOLOG option.
sqlplus /nolog @myscript
Oracle 11gR2
I ran a .sql file via SQL*Plus connected initially as JOHN. Within the file I connect as SYS and then run a GRANT. See .sql file contents below:
connect sys/password as sysdba
GRANT EXECUTE ON DBMS_CRYPTO TO JOHN;
connect JOHN/DOE
NOTE: I don't recommend keeping the sys/password in a text file btw.
HTH
精彩评论