【发布时间】:2011-07-12 08:55:12
【问题描述】:
我有一个返回游标的 oracle sql 存储过程。 此游标在存储过程主体中获取复杂选择语句的值(在下面的示例中,我使选择语句变得简单)。
然后,我想将光标用于两件事: 1.作为存储过程的返回值 2. 使用它的数据来更新存储过程体中另一个表中的一些值
我不知道怎么做,所以同时我不得不复制(复杂的)select语句并让另一个游标有它的值来更新另一个表。
create or replace procedure sp_GetBuildings(returned_cursor OUT SYS_REFCURSOR,
timeFrameHrsParam number) is
v_buildingID Buildings.buildingId%type;
cursor t_result is
select customerId
from (select buildingId from Buildings) b
inner join Customers c on c.building_id = b.building_id;
begin
open returned_cursor for
select customerId
from (select buildingId from Buildings) b
inner join Customers c on c.building_id = b.building_id;
for t in t_result
loop
v_buildingID := t.building_id;
update Buildings set already = 1 where building_id = v_buildingID ;
end loop;
commit;
end sp_GetBuildings;
你能帮我找到一个解决方案来节省我的 select 语句复制吗?
【问题讨论】: