Oracle 尝试在通过pl SQL循环时插入到表中
我有一个视图,需要循环使用另一个表中的所有库存ID。我一直收到以下错误:错误报告-Oracle 尝试在通过pl SQL循环时插入到表中,oracle,plsql,Oracle,Plsql,我有一个视图,需要循环使用另一个表中的所有库存ID。我一直收到以下错误:错误报告- ORA-06550: line 31, column 31: PLS-00357: Table,View Or Sequence reference 'MISSINGINVENTORY' not allowed in this context ORA-06550: line 31, column 2: PL/SQL: SQL Statement ignored 06550. 00000 - "line %s,
ORA-06550: line 31, column 31:
PLS-00357: Table,View Or Sequence reference 'MISSINGINVENTORY' not allowed in this context
ORA-06550: line 31, column 2:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
这是我当前的代码,我不确定问题出在哪里?我对pl sql相当陌生
DECLARE
CURSOR inventory_ids_c IS
SELECT DISTINCT fzrfbth_status status,
fzbfbth_inventory_id id
FROM fzbfbth@develop_sw,
fzrfbth@develop_sw
WHERE fzbfbth_inventory_id = fzrfbth_inventory_id
ORDER BY fzrfbth_status,
fzbfbth_inventory_id;
inventory_ids_rec inventory_ids_c%ROWTYPE;
BEGIN
OPEN inventory_ids_c;
FETCH inventory_ids_c INTO inventory_ids_rec;
LOOP
EXIT WHEN inventory_ids_c%NOTFOUND;
fzkfims.P_set_inventory_id@develop_sw(inventory_ids_rec.id);
DECLARE
CURSOR inventory_items IS
SELECT *
FROM fzvfims@develop_sw;
BEGIN
OPEN inventory_items;
LOOP
FETCH inventory_items INTO Missinginventory(last_inventory_date,
atype_title
,
owner, orgn_code, orgn_title, locn_code, room, bldg, sort_room,
ptag
,
manufacturer, model, serial_num, description, custodian, po,
acq_date,
amount,
ownership, schev_year, tag_type, inventory_id, condition,
asset_type
);
EXIT WHEN inventory_items%NOTFOUND;
END LOOP;
CLOSE inventory_items;
END;
END LOOP;
END;
似乎您正试图从游标直接获取
missingenventory
表(如果它是一个表)。那不行。首先获取游标变量,然后将这些变量插入表中
我不知道这是什么:
fzkfims.P_set_inventory_id@develop_sw(inventory_ids_rec.id);
是的;看起来像是程序调用。我猜它设置了某种“环境”,但我不知道它如何反映到您编写的代码中
无论如何:为什么要使用光标循环?不能直接将数据插入表中吗?这将更快,而且希望更简单
另外,如果您声明了一些东西,请在PL/SQL过程开始时的同一位置进行声明。如果将声明分散在代码中,则很难维护它。此外,请查看cursorFOR
循环是否是一个选项,因为它们更易于使用-Oracle为您做了很多事情。怎样尽管您仍然需要编写游标的SELECT
语句,但不必声明游标变量、打开游标、获取、退出循环以及关闭游标。我将尝试重写您的代码,看看(正如您所看到的,根本没有declare
section!)
什么类型的对象是
丢失的Inventory
?表、视图或?我仍在测试您建议的解决方案,但作为一些附加细节,fzkfims.p_set_清单_id@develop_sw(cur_1.id);用于设置必须设置才能使用FZVFIMS视图的id。其目的是循环遍历fzbfbth表中的ID,并将每个ID返回的所有信息插入新表中。例如,如果id为1-5,它会将id设置为1运行fzvfims视图将所有信息拉入missinginventory表转到下一个id执行相同操作,依此类推。非常感谢你的回复,我会让你知道事情的进展!
begin
for cur_1 in (select distinct fzrfbth_status status,
fzbfbth_inventory_id id
from fzbfbth@develop_sw
join fzrfbth@develop_sw
on fzbfbth_inventory_id = fzrfbth_inventory_id
order by fzrfbth_status,
fzbfbth_inventory_id
)
loop
fzkfims.p_set_inventory_id@develop_sw(cur_1.id);
for cur_2 in (select *
from fzvfims@develop_sw
)
loop
-- I shortened it to just a few columns
insert into missinginventory
(last_inventory_date,
atype_title,
asset_type)
values (cur_2.last_inventory_date,
cur_2.atype_title,
cur_2.asset_type);
end loop;
end loop;
end;