以 sys 作为 sysdba 执行 sql 语句

Execute sql statement as sys as sysdba

我在连接到 sqlplus 的脚本中执行了一个 sql 语句并执行了一些 GRANTS 语句。在 bash 脚本中,指令类似于:

sqlplus sys as sysdba @script.sql

但我需要添加密码。我怎样才能在一行中完成?

我试过了:

sqlplus "sys as sysdba"/password @script.sql

或没有 " 但它不起作用。 谢谢

可以这样执行:

sqlplus sys/password as sysdba @script.sql

示例 1

oracle@esmd:~> sqlplus /  as sysdba @ulcase1.sql

SQL*Plus: Release 11.2.0.3.0 Production on Fri Feb 21 12:07:50 2020

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production

Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
oracle@esmd:~>

示例 2

oracle@esmd:~> sqlplus sys/password  as sysdba @ulcase1.sql

SQL*Plus: Release 11.2.0.3.0 Production on Fri Feb 21 12:08:44 2020

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production

Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
oracle@esmd:~>

示例 3

oracle@esmd:~> sqlplus sys/password@esmd  as sysdba @ulcase1.sql

SQL*Plus: Release 11.2.0.3.0 Production on Fri Feb 21 12:14:49 2020

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production

Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
oracle@esmd:~>