【发布时间】:2015-06-27 10:50:16
【问题描述】:
我正在使用 PL/SQL 开发人员,我使用的数据库是 Oracle 11G R2 数据库和 Visual Studio 2013。我也使用 ODP.net。
目前我使用存储过程为一组学生加载数据,例如 ClassNumber、Ethnicity 等。我加载的数据取决于最终用户的请求。
在我为各个学生加载数据后,我想记录所请求学生的数据。现在我知道如何做到这一点的唯一方法是通过传入单个 StudentBioId 并传入 StudentBioIdentifiers 数组来为每个请求的学生进行数据库调用。 StudentBioIdentifier 是与学生信息相关的标识符,例如 ClassNumber、Ethnicity 等。
我最初的想法是将一组 StudentIds 和一组 StudentBioIds 传递到存储过程中,但我无法将 StudentBioId 与 Student 相关联,因为学生 A 的 Ethnicity 值可能为 XYZ 但学生 B 可能有ABC 种族值。如何在不进行繁重的选择查询的情况下确定哪个 StudentBioId 属于该学生?
我的目标是加快数据插入速度、正确插入数据并可能减少数据库调用。
所以目前我的存储过程中的代码如下所示:
CREATE OR REPLACE TYPE StudentBioIdArray IS VARRAY(100) OF NUMBER(2);
PROCEDURE InsertDummyStudentAuditData(studentID IN NUMBER, studentBioIds IN StudentBioIdArray) IS
BEGIN
IF studentBioIds IS NOT NULL AND studentBioIds.Count > 0 THEN
FORALL i IN 1..studentBioIds.COUNT
INSERT INTO audit_table(Id, Student_id, StudentBioId)
VALUES (-1, studentID, studentBioIds(i));
END IF;
END InsertDummyStudentAuditData;
问题
-即使我为每个学生调用存储过程,它仍然会 更快?
-有更好的选择吗?
【问题讨论】:
-
您想加快插入速度 - 但您真的确定这段代码是瓶颈吗?您是否测量了时间并收集了一些指标?您是否分析了系统在数据插入过程中花费大部分时间的部分? Pheraps 这不是这段代码的问题,而是网络问题,还是别的什么?你要插入多少次,每秒 10 次、每秒 100 次、每秒 1000 次?
标签: database oracle performance plsql insert-into