从 c# 执行写为 .sql 文件(例如:spool.sql)的 oracle spool 命令,就像使用 OracleCommand 执行任何 oracle 查询一样

Posted

技术标签:

【中文标题】从 c# 执行写为 .sql 文件(例如:spool.sql)的 oracle spool 命令,就像使用 OracleCommand 执行任何 oracle 查询一样【英文标题】:Executing oracle spool command which is written as a .sql file(eg:spool.sql) from c# just like executing any oracle query using OracleCommand 【发布时间】:2013-09-04 18:52:15 【问题描述】:

我有一个文本文件,让我们说“createfeed.sql”,其中包含 pl/sql 中使用的set 命令,例如:

set pagesize,
set linesize, 
blah, 
blah,
blah,

然后是一个假脱机命令,它将创建一个文件。

所以我想从 C# 执行这个 createfeed.sql。当我尝试将文件名作为 OracleCommand 参数提供时,它会给出错误,因为它不是那样的。

那么有没有更好的方法在 C# 中执行这个 createfeed.sql 脚本?

我发现的一种方法是使用“进程”启动“pl/sql”然后执行脚本,但我无法成功执行脚本。

【问题讨论】:

【参考方案1】:

你可以试试这样的:

  string myCommand = PSQLCommand;
  //This would be the location of your file
  string myArguments = "PSQLArugments";
    Process.Start(myCommand, myArguments);

So your command would look like psql.exe \i "Path of createfeed.sql"
myCommand would = psql.exe (the full path to your executable)
myArguments = @"\i \pathToCreateFeed.sql"

【讨论】:

psql.exe 是 PostgreSQL 的前端,与 Oracle 无关。 但是我见过很少的代码sn-ps虽然他们没有工作使用进程对象来调用plsql.exe然后执行命令?

以上是关于从 c# 执行写为 .sql 文件(例如:spool.sql)的 oracle spool 命令,就像使用 OracleCommand 执行任何 oracle 查询一样的主要内容,如果未能解决你的问题,请参考以下文章