【问题标题】:How to execute sqlplus commands on cmd.exe?如何在 cmd.exe 上执行 sqlplus 命令?
【发布时间】:2013-09-22 00:49:55
【问题描述】:

我的 sqlplus 命令没有完成,它在密码行等待,它没有给我错误。

当我打开新的 cmd 窗口并粘贴此代码时,此代码没有问题!一切都好, 但我无法使用 process() 在 c# 上运行;

我的sqlplus命令文本:

Set ORACLE_SID=prod
Set ORACLE_HOME=C:\oracle\product\10.2.0\db_1
sqlplus -s 
sys as sysdba
password
shutdown immediate
startup mount
recover standby database until cancel;
cancel
alter database open read only;
exit;
exit;

我试试这个:

C:\cmd.cmd
*********************************************
Set ORACLE_SID=prod
Set ORACLE_HOME=C:\oracle\product\10.2.0\db_1
sqlplus -s 
sys as sysdba
manager
select * from dual;
exit;
*********************************************

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\cmd.cmd";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;

process = Process.Start(startInfo);

//output
string BatProcessResult = process.StandardOutput.ReadToEnd();

输出:

D:\AppPath\bin\Debug>设置 ORACLE_SID=prod

D:\AppPath\bin\Debug>设置 ORACLE_HOME=C:\oracle\product\10.2.0\db_1

D:\AppPath\bin\Debug>sqlplus -s

D:\AppPath\bin\Debug>sys as sysdba;

【问题讨论】:

  • 我记不太清了,但在脚本中是这样的:sqlplus -s "sys@wherever/password as sysdba"。由于空格,所以需要双引号。
  • 谢谢我找到了解决方案,语法 username/pw@db
  • 非常好——很高兴你找到了它!双引号可能是 unix/linux 的东西。请注意,Oracle 将接受 username/pw@dbusername@db/pw

标签: oracle command-line process command-line-arguments sqlplus


【解决方案1】:

试试

sqlplus -L username/pw@db @ fileWithCommands.sql

set ORACLE_SID=...
sqlplus -L / as sysdba

这不会等待用户名和密码,而是使用给定的凭据登录。如果它们错了,sqlplus 将立即退出并出现错误。如果凭据正确,sqlplus 将一个接一个地运行给定文件中的所有命令。

【讨论】:

    【解决方案2】:

    您忘记将用户角色附加到您的命令中。尝试使用这个

    sqlplus <username>/<password>@<host>:<port>/<sid> <db_role> @<script>
    

    例如:

    sqlplus sys/oracle@localhost:1524/ORCL AS SYSDBA @myscript.sql
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      相关资源
      最近更新 更多