【发布时间】:2019-10-29 11:47:40
【问题描述】:
我有一个如下所示的触发器:
create or replace trigger xxlm_rms_mdm123_aid
for insert or delete on uda_item_lov
compound trigger
type xxlm_rms_mdm123_aid_rec is record(
item item_master.item%TYPE,
uda_value uda_item_lov.uda_value%TYPE);
type xxlm_rms_mdm123_aid_tbl is table of xxlm_rms_mdm123_aid_rec index by pls_integer;
L_ctgpro_flag number;
L_data_tbl xxlm_rms_mdm123_aid_tbl;
L_data_tbl_idx number;
L_item item_master.item%TYPE;
L_wldpro_uda_id code_detail.code_desc%TYPE;
L_ctgpro_uda_id code_detail.code_desc%TYPE;
L_wldpro_uda_value uda_item_lov.uda_value%TYPE;
before statement is
begin
L_data_tbl.delete;
L_data_tbl_idx := 0;
end before statement;
before each row is
begin
select sign(count(1))
into L_ctgpro_flag
from code_detail cd
where cd.code_type = 'X123'
and cd.code = 'CTGPRO'
and cd.code_desc = coalesce(:new.uda_id, :old.uda_id);
if L_ctgpro_flag = 1 then
L_data_tbl_idx := L_data_tbl_idx + 1;
L_data_tbl(L_data_tbl_idx).item := coalesce(:old.item, :new.item);
L_data_tbl(L_data_tbl_idx).uda_value := coalesce(:old.uda_value,
:new.uda_value);
end if;
end before each row;
after statement is
begin
if L_data_tbl.count > 0 then
select max(code_desc)
into L_wldpro_uda_id
from code_detail
where code_type = 'X123'
and code = 'WLDPRO';
select max(code_desc)
into L_ctgpro_uda_id
from code_detail
where code_type = 'X123'
and code = 'CTGPRO';
if L_wldpro_uda_id is not null then
for idx in 1 .. L_data_tbl.count loop
L_item := L_data_tbl(idx).item;
select max(substr(uv.uda_value_desc, 1, 2))
into L_wldpro_uda_value
from uda_values uv
where uv.uda_id = L_ctgpro_uda_id
and uv.uda_value = L_data_tbl(idx).uda_value;
if L_wldpro_uda_value is not null then
if inserting then
insert into uda_item_lov
(item,
uda_id,
uda_value,
create_datetime,
last_update_datetime,
last_update_id)
values
(L_item,
L_wldpro_uda_id,
L_wldpro_uda_value,
sysdate,
sysdate,
user);
elsif deleting then
delete uda_item_lov
where item = L_item
and uda_id = L_wldpro_uda_id
and uda_value = L_wldpro_uda_value;
end if;
end if;
end loop;
end if;
end if;
end after statement;
end;
它给出了一个数字错误,即 L_data_tbl_idx 为空。对我来说它看起来很奇怪,因为它应该用 before 语句初始化。 如果我在声明期间初始化变量,就像这样
L_data_tbl xxlm_rms_mdm123_aid_tbl;
L_data_tbl_idx number := 0; -- <-- here it is
L_item item_master.item%TYPE;
它工作正常。有人可以告诉我这里发生了什么以及为什么在第一种情况下没有初始化变量吗?谢谢!
【问题讨论】:
-
请问您收到的确切错误信息是什么?我的猜测是
l_data_tbl_idx不是 null,而是l_data_tbl(l_data_tbl_idx)是。 -
引发“ORA-06502: PL/SQL: numeric or value error: NULL index table key value”