Is there a .Net interface to Oracle SQLPLUS?

前端 未结 2 1348
野的像风
野的像风 2021-01-12 08:47

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 t

2条回答
  •  抹茶落季
    2021-01-12 09:28

    It took me a while to figure out how to make it all work so here is the result of my investigations:

    c# code:

    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
     ...
    

    Resulting command line:

    sqlplus.exe user/pwd@db @c:\tmp.sql 'Oracle sucks!'

    Type sqlplus /? in a dos prompt and you'll get the syntax:

    sqlplus

    Here logon=user/pwd@db and start=@c:\tmp.sql 'Oracle sucks!'

    It will start the sql file and pass it the parameter string.

    tmp.sql first line:

    prompt &1

    will display the parameter string.

    Thx

提交回复
热议问题