是否存在Oracle SQLPLUS的.Net接口? [英] Is there a .Net interface to Oracle SQLPLUS?
问题描述
我正在开发一些自动化方法来控制SQL脚本的执行.这些脚本通过 SQL * PLUS 运行,并在其中包含 PL/SQL 调用(因此,我无法通过 ODP.NET 运行它们)
I'm developing some automation to control the execution of SQL scripts. The scripts are run through SQL*PLUS and contain PL/SQL calls in them (hence I can't run them through ODP.NET).
我想知道是否有 .NET 与 SQL * PLUS 的接口?如果有的话,有人使用过吗?
I was wondering if there was a .NET interface to SQL*PLUS? If so has anyone used it?
推荐答案
我花了一些时间弄清楚如何使其全部正常工作,所以这是我的调查结果:
It took me a while to figure out how to make it all work so here is the result of my investigations:
c#代码:
ORAUtils.execString(@"c:\tmp.sql 'Oracle sucks!'");
...
using System.Diagnostics; -- where the Process stuff lives
...
public static int execString(string scriptFileName)
{
...
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = "sqlplus.exe";
processInfo.Arguments = "user/pwd@db @" + scriptFileName;
...
Process process = Process.Start(processInfo); // typo in code above small p instead of caps helps
...
结果命令行:
sqlplus.exe用户/pwd @ db @c:\ tmp.sql'Oracle很烂!'
sqlplus.exe user/pwd@db @c:\tmp.sql 'Oracle sucks!'
输入sqlplus/?在dos提示下,您将获得语法:
Type sqlplus /? in a dos prompt and you'll get the syntax:
sqlplus
这里登录=用户/pwd @ db并开始= @ c:\ tmp.sql'Oracle很烂!'
Here logon=user/pwd@db and start=@c:\tmp.sql 'Oracle sucks!'
它将启动sql文件并向其传递参数字符串.
It will start the sql file and pass it the parameter string.
tmp.sql第一行:
tmp.sql first line:
提示& 1
将显示参数字符串.
Thx
这篇关于是否存在Oracle SQLPLUS的.Net接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!