create or replace procedure placeorder(
itemid in tempcart.item_id%type,num in integer,cid in customer_info.cust_id%type)
is
cnt integer;
amt integer;
next_id number(5);
temp tempcart%rowtype;
cursor temp2 is select * from tempcart where tempcart.item_id=itemid;
cursor temp1 is select * from tempcart;
BEGIN
cnt:=0;
select count(*) into cnt from porder;
select max(oid) into next_id from porder;
if(cnt=0) then
next_id:=1;
else
next_id:=next_id+1;
end if;
if(num=1) then
insert into corder values(next_id,itemid);
select amount into amt from tempcart where item_id=itemid;
insert into porder values(next_id,amt,sysdate);
open temp2;
fetch temp2 into temp;
insert into history values (itemid,temp.pid,temp.quantity,temp.amount,cid,temp.name);
else
amt:=0;
open temp1;
loop
fetch temp1 into temp;
exit when temp1%notfound;
insert into corder values(next_id,temp.item_id);
amt:=amt+temp.amount;
insert into history values(temp.item_id,temp.pid,temp.quantity,temp.amount,cid,temp.name);
end loop;
insert into porder values(next_id,amt,sysdate);
end if;
end placeorder;
这个程序有什么问题?当我使用 placeorder(1,1,2)
调用它时,它只在 corder
中插入值,但不在 porder
中插入 .
1 回答
对不起,我无法重现这一点 .
您没有向我们提供您正在使用的表格,也没有提供其中的任何数据,因此我使用了表格
和数据
然后我跑了
这样做之后,我可以验证
corder
和porder
都被插入,history
表也是如此:因此,很难看出你的问题是什么 .
我注意到你没有关闭你的游标
temp1
和temp2
. 使用CLOSE temp1
和CLOSE temp2
后,请在完成后立即尝试关闭它们 .