用两个游标给你个例子,变量未定义和说明
declare cur_sales cursor for
select order_no from sales order by order_no
open cur_sales
fetch next from cur_slaes into @v_order_no
while (@@fetch_status<>-1)
begin
declare cur_item cursor for
select prod_id,sup_id,qty,unit_price
from sale_item where order_no=@v_order_no
ordre by pro_id,sup_id
open cur_item
fetch next from cur_item into .....
while (@@fetch_status<>-1)
begin
fetch next from cur_item into ..
end
close cur_item
deallocate cur_item
fetch next from cur_sales into ..
end
close cur_sales
deallocate cur_sales
//其实可以根据关系和为一个游标
//如果结构相同也可以用union all