он не присваивается связанным полям BULK COLLECT INTO l_mothers, и я столкнулся с необъявленным идентификатором.
Я пытаюсь присвоить результат, возвращенный запросом, таблице с массовым сбором. Я попытался запуститьс отладкой.В следующем коде я подробно объяснил ситуацию и поделился выводом на экран.
CREATE OR REPLACE function YKD.z_fnc_get_child_piece_from_hist_hr_tst(p_piece_num_id number) return number
is
n_child_piece_num_id number;
v_session_id number := SYS_CONTEXT('USERENV','sessionid')||to_number(to_char(sysdate,'hh24miss'));
PRAGMA AUTONOMOUS_TRANSACTION;
v_piece_id varchar2(20);
v_product_type varchar2(20);
v_steel_grade varchar2(20);
v_actual_thisck number;
v_piece_status number;
vt_father_num_id number;
vt_father_num_id1 number;
vt_father_id varchar2(20);
vt_father_p_type varchar2(20);
vt_steel_grade_id varchar2(20);
vt_product_type varchar2(20);
vt_actual_thick number;
v_sch_line_num_id number;
vt_mod_datetime date;
vt_piece_supplier varchar2(20);
vv_mod_datetime date;
n_child_piece_num_id1 number;
TYPE t_mothers IS RECORD (
sch_line_num_id number,
piece_num_id number,
piece_id varchar2(20),
product_type varchar2(20),
internal_steel_grade_id varchar2(20),
actual_thick number,
actual_weight number,
ord_product_type varchar2(20),
mod_datetime date,
piece_supplier varchar2(20));
TYPE tbl_mothers IS TABLE OF t_mothers INDEX BY PLS_INTEGER;
l_mothers tbl_mothers;
Сначала я создал функцию и объявил поля.
BEGIN
--control piece id is exists
select piece_id,product_type,internal_steel_grade_id ,actual_thick,piece_status_num_id
into v_piece_id,vt_product_type,v_steel_grade,v_actual_thisck,v_piece_status
from piece
where piece_num_id = p_piece_num_id
and piece_status_num_id != 0;
IF vt_product_type like 'PH%P' THEN
select phi.piece_num_id as father_num_id,
pf.product_type,
pf.internal_steel_grade_id ,pf.actual_thick,
sch_line_num_id,
pf.mod_datetime,
(select attrb_an_value from piece_attrb where piece_num_id = phi.piece_num_id and attrb_code = 'PIECE_SUPPLIER') piece_supplier
into vt_father_num_id1,
vt_product_type,
vt_steel_grade_id,vt_actual_thick,
v_sch_line_num_id,
vt_mod_datetime,
vt_piece_supplier
from piece pf,
piece_history_in phi,
piece_history ph,
piece_history_out pho
where ph.status = 2
and phi.piece_num_id = pf.piece_num_id
and ph.piece_history_num_id = phi.piece_history_num_id
and ph.piece_history_num_id = pho.piece_history_num_id
and pho.piece_num_id = p_piece_num_id
and rownum = 1;
else
vt_father_num_id1 := p_piece_num_id;
end IF;
IF vt_father_num_id1 is not null then
--find mother piece
select phi.piece_num_id as father_num_id,
pf.internal_steel_grade_id ,pf.actual_thick,
sch_line_num_id,
pf.mod_datetime,
(select attrb_an_value from piece_attrb where piece_num_id = phi.piece_num_id and attrb_code = 'PIECE_SUPPLIER') piece_supplier
into vt_father_num_id,
vt_steel_grade_id,vt_actual_thick,
v_sch_line_num_id,
vt_mod_datetime,
vt_piece_supplier
from piece pf,
piece_history_in phi,
piece_history ph,
piece_history_out pho
where ph.status = 2
and phi.piece_num_id = pf.piece_num_id
and ph.piece_history_num_id = phi.piece_history_num_id
and ph.piece_history_num_id = pho.piece_history_num_id
and pho.piece_num_id = vt_father_num_id1 --p_piece_num_id
and rownum = 1;
IF v_sch_line_num_id is not null then
select tt.sch_line_num_id,tt.piece_num_id,
p.piece_id,p.product_type,p.internal_steel_grade_id ,p.actual_thick,
p.actual_weight,tt.ord_product_type,p.mod_datetime,
(select attrb_an_value from piece_attrb where piece_num_id = p.piece_num_id and attrb_code = 'PIECE_SUPPLIER') piece_supplier
BULK COLLECT INTO l_mothers
from
(select sl.sch_line_num_id,
(select sip.piece_num_id
from sch_input_material sim,
sch_input_piece sip
where sim.sch_line_num_id = sl.sch_line_num_id
and sip.input_mat_num_id = sim.input_mat_num_id) piece_num_id,
(select (select attrb_an_value
from config_attrb_of_so_line
where so_id = ppo.so_id
and so_line_id = ppo.so_line_id
and attrb_code = 'PRODUCT_GROUP_SO')
from plan_po_order_detail ppo
where plan_po_num_id = sl.plan_po_num_id) ord_product_type
from sch_line sl
where 1 = 1
and exists (select 1
from sch_line sll
where sll.sch_line_num_id = v_sch_line_num_id
and sll.sch_num_id = sl.sch_num_id
and sll.lev2_status = 20
and sll.status = 1)
and sl.lev2_status = 20
and sl.status = 1) tt,
piece p
where p.piece_num_id = tt.piece_num_id
and tt.ord_product_type = vt_product_type
and p.actual_thick = vt_actual_thick
and p.internal_steel_grade_id = vt_steel_grade_id;
end if;
end if;
Затем для освобожденных полей:Я установил некоторые критерии и запросы и заметил, что BULK COLLECT INTO l_mothers не заполняет никакие значения для полей.
FOR indx IN 1 .. l_mothers.COUNT
loop
IF l_mothers(indx).piece_supplier = vt_piece_supplier THEN
Begin
select ms.piece_num_id
into n_child_piece_num_id
from mech_sample ms
where ms.piece_num_id = l_mothers(indx).piece_num_id
and ms.status NOT IN (80, 90)
and exists ( select 1
from mech_scheduled_test mst,
mech_scheduled_property msp,
mech_property_result mpr
where mst.sample_num_id = ms.sample_num_id
AND msp.mst_num_id = mst.mst_num_id
AND msp.status NOT IN (80, 90)
AND mpr.msp_num_id = msp.msp_num_id
AND EXISTS (SELECT mp.PROPERTY_ID
FROM mech_test_property mp,
z_tmp_table_qc qc
WHERE mp.PROPERTY_NUM_ID = msp.PROPERTY_NUM_ID
AND qc.PROPERTY_ID = mp.property_id
and qc.type = 2) );
exception
when no_data_found then
n_child_piece_num_id := null;
end;
IF n_child_piece_num_id is not null then
IF n_child_piece_num_id1 is null then
n_child_piece_num_id1 := n_child_piece_num_id;
ELSIF l_mothers(indx).mod_datetime between vv_mod_datetime and vt_mod_datetime then
n_child_piece_num_id1 := n_child_piece_num_id;
end IF;
end IF;
end IF;
/* insert into Z_TMP_TABLE07 (sch_line_num_id,piece_num_id,piece_id,product_type,
steel_grade_id,actual_thick,actual_weight,ord_product_type,
mec_product_num_id,mod_datetime,
session_id)
values (l_mothers(indx).sch_line_num_id,l_mothers(indx).piece_num_id ,
l_mothers(indx).piece_id ,l_mothers(indx).product_type ,
l_mothers(indx).piece_supplier ,l_mothers(indx).actual_thick ,
l_mothers(indx).actual_weight ,l_mothers(indx).ord_product_type ,
n_child_piece_num_id1,l_mothers(indx).mod_datetime,
v_session_id); */
end loop;
-- commit;
return(n_child_piece_num_id1);
end;
l_mothers не может заполнить, поэтому не возвращайте n_child_piece_num_id1.
Я ожидаю вывода таблицы значений. Но, похоже, ошибка «необъявленный идентификатор» для всех полей.