从 Oracle 的 C# 脚本输出中读取
Posted
技术标签:
【中文标题】从 Oracle 的 C# 脚本输出中读取【英文标题】:Read from C# script output from Oracle 【发布时间】:2013-09-13 15:32:24 【问题描述】:我自己无法弄清楚如何在我的 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
【问题讨论】:
这里有一个答案:***.com/a/12303416/570191 【参考方案1】:我只需要创建一些表,比如“INTERVALS”和一些列,比如“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.
【讨论】:
不错的快速技巧。特别是如果您只想从 C# 调试 plsql 函数。以上是关于从 Oracle 的 C# 脚本输出中读取的主要内容,如果未能解决你的问题,请参考以下文章