我們有一個查詢將按月執行並返回大小爲1GB的數據。從oracle數據庫讀取大量數據並使用C#將其導出爲.dat文件
此處使用的查詢只是包含內部連接的選擇查詢,不涉及遊標。
目前他們正在Toad中執行此查詢並將數據從輸出窗口導出爲.dat文件。
請注意,使用蟾蜍手動操作需要2小時。
之後,他們正在更改.dat文件中的標題文本,使其具有有意義的名稱與我們的客戶共享。
我想通過創建一個將執行此過程的exe來自動執行此過程。
代碼快照看起來像下面
using (OracleConnection conn = new OracleConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
conn.Open();
using (OracleCommand cmd = new OracleCommand(commandText))
{
cmd.Connection = conn;
using (OracleDataReader dtReader = cmd.ExecuteReader())
{
outputContent = new StringBuilder();
while (dtReader != null && dtReader.Read())
{
for (int i = 0; i < dtReader.FieldCount; i++)
{
outputContent.Append(dtReader[i]);
outputContent.Append(delimiter);
}
outputContent = outputContent.Replace(delimiter, Environment.NewLine, outputContent.Length - 1, 1);
}
}
}
}
outputPath = string.Format(ConfigurationManager.AppSettings["OutputPath"], DateTime.Now.Ticks);
outputStream = new StreamWriter(outputPath, true);
//Export
outputStream.Write(outputContent.ToString());
outputStream.Close();
從日誌中,它得到了OT知道,執行讀者語句秒內完成。
但從DataReader的讀取數據拋出 「異常信息是ORA-03113:結束文件在System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle,的Int32 RC)上的通信信道 」 8小時後時間。
任何人都可以請讓我知道上面的方法是好的處理1GB大小的數據?或
有沒有其他更好的方法來做到這一點?
感謝, Gayathri
感謝您的建議.Query根據當前的月份在where條件中取代了一些月份值。我計劃相應地爲每個月份的thro代碼更改cmd文本。標題需要更改在輸出內容中。所有這些可能需要以上建議手動中斷。 – Gayathri
請記住,您可以從shell將參數傳遞給PlSql(有關unix中的示例,請參閱http://www.dbforums.com/oracle/1214698-procedure-call-through-shell-script.html)和/或運行shell或PlSql來自C#的代碼。 –