oracle CONNECT 应该在 SQL*PLUS 脚本中工作吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2156294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:53:48  来源:igfitidea点击:

Should CONNECT work in SQL*PLUS script?

oraclesqlplus

提问by wadesworld

I'd like to run a sqlplus script from a cron job.

我想从 cron 作业运行 sqlplus 脚本。

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?

我误解了connect命令的用法吗?

采纳答案by Quassnoi

When running CONNECTinside SQL*Plus, remove the quotes:

CONNECTinside运行时SQL*Plus,删除引号:

CONNECT myuser/mypass@mydb

They double quotes are required if you are passing the credentials as an argument to sqlplus:

如果您将凭据作为参数传递给sqlplus

sqlplus "myuser/mypass@mydb"

, for the shell to parse myuser/mypass@mydbas a single argument if you have spaces in your connection identifier or use additional options like AS SYSDBA.

,myuser/mypass@mydb如果连接标识符中有空格或使用其他选项(如AS SYSDBA.

回答by Jeffrey Kemp

Use the /NOLOG option.

使用 /NOLOG 选项。

sqlplus /nolog @myscript

回答by tale852150

Oracle 11gR2

甲骨文 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:

我通过最初作为 JOHN 连接的 SQL*Plus 运行了一个 .sql 文件。在文件中,我以 SYS 身份连接,然后运行 ​​GRANT。请参阅下面的 .sql 文件内容:

connect sys/password as sysdba

将 sys/password 连接为 sysdba

GRANT EXECUTE ON DBMS_CRYPTO TO JOHN;

将 DBMS_CRYPTO 上的执行授权给 JOHN;

connect JOHN/DOE

连接约翰/美国能源部

NOTE: I don't recommend keeping the sys/password in a text file btw.

注意:顺便说一句,我不建议将系统/密码保存在文本文件中。

HTH

HTH