我无法弄清楚如何在c#app中读取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
答案 0 :(得分:1)
我只需要创建一些表,让我们说'INTERVALS'和一些列,让我们说'To_Task_ID'和'Trigs'并插入过程简单的Insert命令,如下所示。
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.