调整插入Oracle数据库

时间:2014-07-01 09:34:44

标签: oracle

关于插入Oracle数据库的问题...我有代码示例(如下),此代码将500条记录插入到db ..但是插入500条记录需要3分钟...目前为止因为我知道表有索引,服务器是全新的,非常快,我做了一些关于网络速度的测试,一切都好,所以我怀疑是我的#34;插入代码&#34 ;不是很好......有没有一种方式可以加速"加速"插入或者还有其他我忽略的东西......所以任何建议都很好......谢谢!

这是"插入"代码示例:

 myQuery = " INSERT INTO AGR3PL_LINE (IDOC_NUM, SEG_NUM, LINN02, WMLI02, CATN02, LQTY02, IUNT02, TOWT02, WUOM02, DTDR02, ORDL02, LOCN02, DEXP02, DPRO02, NOTS02, " +
                                          " PNUM05, PDES05, PTYP05, PCLS05, IUNT05, SUNT05, PUNT05, ISCF05, SPCF05, SHLU05, SHLF05, CSHL05, BATC05, BARC05, ANAC05, WTSU05, WTBU05, CWIT05, DFSS05) " +
                                          " VALUES (" + Lidoc_num + ",'" +
                                                        SEG_NUM_L + "'," +
                                                        (!dr_art_line.Table.Columns.Contains("LineNumber") || dr_art_line["LineNumber"].ToString().Length <= 0 ? 0 : dr_art_line["LineNumber"]) + "," +
                                                        WMLI02 + ",'" +
                                                        (!dr_art_line.Table.Columns.Contains("ItemNumber") || dr_art_line["ItemNumber"].ToString().Length <= 0 ? string.Empty : dr_art_line["ItemNumber"]) + "','" +
                                                        QuantityInIssueUnit_value + "','" +
                                                        QuantityInIssueUnit_uom + "'," +
                                                        QuantityInSecondaryUnit.ToString().Replace(",", ".") + ",'" +
                                                        WUOM02 + "','" +
                                                        DeliveryDate + "'," +
                                                        (!dr_art_line.Table.Columns.Contains("OrderLine") || dr_art_line["OrderLine"].ToString().Length <= 0 ? 0 : dr_art_line["OrderLine"]) + ",'" +
                                                        (!dr_art_line.Table.Columns.Contains("LotNumber") || dr_art_line["LotNumber"].ToString().Length <= 0 ? string.Empty : dr_art_line["LotNumber"]) + "','" +
                                                        ExpirationDate + "','" +
                                                        DateOfProduction + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("Notes") || dr_art_line["Notes"].ToString().Length <= 0 ? string.Empty : dr_art_line["Notes"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("ItemCode") || dr_art_line["ItemCode"].ToString().Length <= 0 ? string.Empty : dr_art_line["ItemCode"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("Description") || dr_art_line["Description"].ToString().Length <= 0 ? string.Empty : dr_art_line["Description"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("ItemType") || dr_art_line["ItemType"].ToString().Length <= 0 ? string.Empty : dr_art_line["ItemType"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("ItemClass") || dr_art_line["ItemClass"].ToString().Length <= 0 ? string.Empty : dr_art_line["ItemClass"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("IssueUnit") || dr_art_line["IssueUnit"].ToString().Length <= 0 ? string.Empty : dr_art_line["IssueUnit"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("StockUnit") || dr_art_line["StockUnit"].ToString().Length <= 0 ? string.Empty : dr_art_line["StockUnit"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("PurchaseUnit") || dr_art_line["PurchaseUnit"].ToString().Length <= 0 ? string.Empty : dr_art_line["PurchaseUnit"]) + "'," +
                                                        IssueToStockConversionFactor.ToString().Replace(",", ".") + "," +
                                                        StockToPurchaseConversionFactor.ToString().Replace(",", ".") + ",'" +
                                                        (!dr_art_line.Table.Columns.Contains("ShelfLifeUnit") || dr_art_line["ShelfLifeUnit"].ToString().Length <= 0 ? 0 : dr_art_line["ShelfLifeUnit"]) + "'," +
                                                        (!dr_art_line.Table.Columns.Contains("ShelfLife") || dr_art_line["ShelfLife"].ToString().Length <= 0 ? 0 : dr_art_line["ShelfLife"]) + "," +
                                                        (!dr_art_line.Table.Columns.Contains("CustomerShelfLife") || dr_art_line["CustomerShelfLife"].ToString().Length <= 0 ? 0 : dr_art_line["CustomerShelfLife"]) + "," +
                                                        MandatoryLot + ",'" +
                                                        (!dr_art_line.Table.Columns.Contains("BarcodeIssueUnit") || dr_art_line["BarcodeIssueUnit"].ToString().Length <= 0 ? string.Empty : dr_art_line["BarcodeIssueUnit"]) + "','" +
                                                        (!dr_art_line.Table.Columns.Contains("BarcodeStockUnit") || dr_art_line["BarcodeStockUnit"].ToString().Length <= 0 ? string.Empty : dr_art_line["BarcodeStockUnit"]) + "'," +
                                                        WeightIssueUnit.ToString().Replace(",", ".") + "," +
                                                        gros_un.ToString().Replace(",", ".") + "," +
                                                        cat_item + ",'" +
                                                        (!dr_art_line.Table.Columns.Contains("DefaultStockStatus") || dr_art_line["DefaultStockStatus"].ToString().Length <= 0 ? string.Empty : dr_art_line["DefaultStockStatus"]) + "')";  

1 个答案:

答案 0 :(得分:0)

如果您在等待事件运行时看到等待事件并且没有什么是明显的,那么最佳方法是跟踪会话。你会在那里找到你的答案。有几种跟踪会话的方法。我使用的那个(假设我不需要登录触发器立即启用它)是:

1)找到会话的spid
  从v $ session s中选择spid,v $ process p其中s.paddr = p.addr和s.sid ='&amp; sid';

2)启用oradebug跟踪(as sysdba)
  oradebug setospid&amp; spid
  oradebug事件10046追踪名称背景永远,等级12

3)找到跟踪文件(检查diag目录。跟踪文件将在文件名中包含spid) - 在linux中,通常“ls -lrt”会将其显示为显示列表中的最后一个文件<登记/>
4)如果要进行汇总,可以在跟踪文件上运行tkprof。如果您需要原始详细信息,请查看“.trc”文件(它将显示所发生的一切,时间和发生的顺序)

5)禁用跟踪(如果会话未注销)
  oradebug setospid&amp; spid   oradebug事件10046跟踪名称上下文关闭