我在Oracle中的BULK COLLECT有问题。我收到“ ORA-06502:PL / SQL:数字或值错误:批量绑定:截断绑定 ORA-06512”,当尝试在下面的代码块末尾填充“ report_tab”时。如您所见,我对其他表使用BULK COLLECT及其工作正常。
我注意到不同数据库中的表之间存在差异。两列在一个数据库中定义为CHAR,在另一数据库中定义为BYTE。现在,我已对此进行了更改,但仍然收到错误。有什么想法吗?
DECLARE
old_schedule_id_ NUMBER;
new_schedule_id_ NUMBER;
TYPE schedule_type IS TABLE OF loc_schedule%ROWTYPE;
schedule_tab schedule_type := schedule_type();
TYPE bindvar_type IS TABLE OF loc_sched_bindvar%ROWTYPE;
bindvar_tab bindvar_type := bindvar_type();
TYPE param_type IS TABLE OF loc_sched_param%ROWTYPE;
param_tab param_type := param_type();
destination_rec loc_sched_destination%ROWTYPE;
format_rec loc_sched_format%ROWTYPE;
TYPE report_type IS TABLE OF loc_client_report%ROWTYPE;
report_tab report_type := report_type();
CURSOR get_schedules(company_id_ IN VARCHAR) IS
SELECT *
FROM loc_schedule@owprod5link s
WHERE s.client_id = company_id_;
CURSOR get_destination(schedule_id_ IN NUMBER) IS
SELECT *
FROM loc_sched_destination@owprod5link sd
WHERE sd.SCHEDULE_ID = schedule_id_;
CURSOR get_format(schedule_id_ IN NUMBER) IS
SELECT *
FROM loc_sched_format@owprod5link sf
WHERE sf.SCHEDULE_ID = schedule_id_;
CURSOR get_bindvar(schedule_id_ IN NUMBER) IS
SELECT *
FROM loc_sched_bindvar@owprod5link bv
WHERE bv.SCHEDULE_ID = schedule_id_;
CURSOR get_params(schedule_id_ IN NUMBER) IS
SELECT *
FROM loc_sched_param@owprod5link par
WHERE par.SCHEDULE_ID = schedule_id_;
CURSOR get_reports(company_id_ IN VARCHAR) IS
SELECT *
FROM loc_client_report@owprod5link r
WHERE r.client_id = company_id_;
BEGIN
OPEN get_schedules(:client_id);
FETCH get_schedules BULK COLLECT INTO schedule_tab;
CLOSE get_schedules;
FOR I IN schedule_tab.first .. schedule_tab.last LOOP
old_schedule_id_ := schedule_tab(I).schedule_id;
new_schedule_id_ := LOC_SCHEDULE_TEST_SEQ.nextval();
schedule_tab(I).schedule_id := new_schedule_id_;
schedule_tab(I).client_id := :new_client_id_;
INSERT INTO loc_schedule_test VALUES schedule_tab(I);
OPEN get_destination(old_schedule_id_);
FETCH get_destination INTO destination_rec;
CLOSE get_destination;
destination_rec.schedule_id := new_schedule_id_;
destination_rec.destination_id :=
LOC_SCHED_DESTINATION_TEST_SEQ.nextval;
INSERT INTO loc_sched_destination_test VALUES destination_rec;
OPEN get_format(old_schedule_id_);
FETCH get_format INTO format_rec;
CLOSE get_format;
format_rec.schedule_id := new_schedule_id_;
format_rec.format_id := LOC_SCHED_FORMAT_TEST_SEQ.nextval;
INSERT INTO loc_sched_format_test VALUES format_rec;
OPEN get_bindvar(old_schedule_id_);
FETCH get_bindvar BULK COLLECT INTO bindvar_tab;
CLOSE get_bindvar;
IF(bindvar_tab.count>0) THEN
FOR I IN bindvar_tab.first .. bindvar_tab.last LOOP
bindvar_tab(I).schedule_id := new_schedule_id_;
bindvar_tab(i).bindvar_id :=
LOC_SCHED_BINDVAR_TEST_SEQ.nextval;
INSERT INTO loc_sched_bindvar_test VALUES bindvar_tab(I);
END LOOP;
END IF;
OPEN get_params(old_schedule_id_);
FETCH get_params BULK COLLECT INTO param_tab;
CLOSE get_params;
IF(param_tab.count>0) THEN
FOR I IN param_tab.first .. param_tab.last LOOP
param_tab(I).schedule_id := new_schedule_id_;
param_tab(i).param_id := LOC_SCHED_PARAM_TEST_SEQ.nextval;
INSERT INTO loc_sched_param_test VALUES param_tab(I);
END LOOP;
END IF;
END LOOP;
OPEN get_reports(:client_id);
FETCH get_reports BULK COLLECT INTO report_tab;
CLOSE get_reports;
FOR I IN report_tab.first .. report_tab.last LOOP
report_tab(I).client_id := :new_client_id_;
INSERT INTO loc_client_report_test VALUES report_tab(I);
END LOOP;
END;
更新:问题已解决!当我将所有表列声明为CHAR而不是BYTE时,它起作用了。