开发者

Should CONNECT work in SQL*PLUS script?

开发者 https://www.devze.com 2022-12-18 14:03 出处:网络
I\'d like to开发者_StackOverflow社区 run a sqlplus script from a cron job. I thought I could put a line like:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消