从 Oracle 的 C# 脚本输出中读取

本文关键字:输出 读取 脚本 Oracle | 更新日期: 2023-09-27 18:31:09

我自己无法弄清楚如何在我的 c# 应用程序中读取 Oracle 的脚本输出。请帮助某人。代码示例如下:
...

 List<DateTime> dtList = new List<DateTime>();                                         
    using (OracleConnection connection = new OracleConnection (connectionString))
         {      
         connection.Open ();
         string sqlText = @" SET SERVEROUTPUT ON;
            Declare  
            start_date        TIMESTAMP;
            return_date_after TIMESTAMP;
            next_run_date     TIMESTAMP;
            BEGIN 
            start_date :=
            to_timestamp_tz('01-JAN-2003 10:00:00','DD-MON-YYYY HH24:MI:SS');
            return_date_after := start_date;
            FOR i IN 1..5 LOOP
            DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING(  
            'freq=weekly; BYDAY=MON,TUE,WED',
            start_date, return_date_after, next_run_date);
            DBMS_OUTPUT.PUT_LINE('next_run_date: ' || next_run_date);
            return_date_after := next_run_date;
            END LOOP;
            END;";                                          
        OracleCommand command = new OracleCommand (sqlText, connection);
        OracleDataReader reader = command.ExecuteReader ();
           while (reader.Read ())
             {
                 dtList.Add((DateTime)reader [ "next_run_date" ]);
             }   
        }           
    ... But it just doesn't enter the while loop, because script output is not in rows. How can I put the following output in rows of some table or maybe read them directly from my app. Thanks 
next_run_date: 06-JAN-03 10.00.00.000000 AM
next_run_date: 07-JAN-03 10.00.00.000000 AM
next_run_date: 08-JAN-03 10.00.00.000000 AM
next_run_date: 13-JAN-03 10.00.00.000000 AM
next_run_date: 14-JAN-03 10.00.00.000000 AM

从 Oracle 的 C# 脚本输出中读取

我只需要创建一些表,让我们说一些列的"间隔",让我们说"To_Task_ID"和"Trigs"并插入到过程简单的插入命令,如下所示。

        DBMS_OUTPUT.PUT_LINE('next_run_date: ' || next_run_date);
        Insert into INTERVALS (to_task_id, trigs) values (i, next_run_date);
        return_date_after := next_run_date;
    END LOOP;
END;  // After which I can easily get this data.