oracle数据库:业务数据处理之四
一、任务
9\在任务7中,采购单的审核只是将单据的状态变成审核而已,事实上,对于采购单的审核确认,还有一件非常重要的事情要做,就是一旦采购单审核确认,那么采购明细表中的商品采购数量应该更新到商品表中,即完成系统中的商品账面入库的操作,如果一张采购单上有多个商品,需要根据每个商品的采购数据来更新商品表中的库存
10\编写根据订单编号审核订单的过程,输入订单编号,进行订单出库处理,即更新商品的库存,要求库存不能小于0,即如果库存不够,不能审核,并提醒用户进行修改。
二PL/SQL
9\子任务的实现
create or replace procedure p_procureupdatestocks
(i_pmid in t_procure_items.pmid%type,o_result out varchar2) as
cursor cur_p_items is select gid,pinum from t_procure_items where pmid=i_pmid;
v_gid t_procure_items.gid%type;
v_pinum t_procure_items.pinum%type;
begin
open cur_p_items;
fetch cur_p_items into v_gid,v_pinum;
while cur_p_items%found loop
update t_good set gstocks=gstocks+v_pinum where gid=v_gid;
fetch cur_p_items into v_gid,v_pinum;
end loop
close cur_p_items;
o_result:='1';
exception
when others then
o_result:=SQLERRM;
end;
任务7中调用子过程的代码改进如下:
create or replace procedure p_checkmainprocure
(i_pmid t_main_procure.pmid%type) as
v_pstate char;
e_checked exception;
v_result varchar2(100);
begin
select pstate into v_pstate from t_main_procure where pmid=i_pmid;
if v_pstate='2' then
raise e_checked;
else
p_procureupdatestocks(i_pmid,v_result);
if v_result='1' then
update t_main_procure set pstate='2' where pmid=i_pmid;
dbms_output.put_line('审核单据'||i_pmid||'成功!');
commit;
else
dbms_output.put_line('采购入账发生错误:'||v_result);
rollback;
return;
end if;
end if;
exception
when e_checked then
dbms_output.put_line('ERROR:'||i_pmid||'单据已经审核!');
when others then
dbms_output.put_line(SQLERRM);
rollback;
end;
10\create or replace procedure p_checkorder
(i_omid in t_main_order.omid%type) as
v_exists number:=0;
v_checked char:='';
cursor cur_items(cv_omid t_main_order.omid%type) is select upper(gid),onum from
t_order_items where omid=cv_omid;
v_gid t_order_items.gid%type;
v_onum t_order_items.onum%type;
begin
select count(omid) into v_exists from t_main_order where omid=i_omid;
if v_exists<1 then
dbms_output.put_line('您输入的单号不正确,请检查以后再操作');
return;
end if;
v_exists:=0;
select ostate into v_checked from t_main_order where omid=i_omid;
if v_checked<>'1' then
dbms_output.put_line('订单不是待审核的状态!');
return;
end if;
select count(omid) into v_exists from t_order_items where omid=i_omid;
if v_exists<1 then
dbms_output.put_line('订单为空单,不能审核!');
return;
end if;
open cur_items(i_omid);
fetch cur_items into v_gid,v_onum;
while cur_items%found loop
v_exists:=0;
select count(gid) into v_exists from t_good where upper(gid)=v_gid and gstocks>=v_onum;
if v_exists>0 then
update t_good set gstocks=gstocks-v_onum where upper(gid)=v_gid;
else
raise_application_error(-20013,v_gid||'商品编号不正确或者库存不够,请重新确认!');
end if;
fetch cur_items into v_gid,v_onum;
end loop;
update t_main_order set ostate='2' where omid=i_omid;
commit;
dbms_output.put_line('订单审核成功,转入发货');
exception
when others then
dbms_output.put_linc(SQLERRM);
rollback;
end;
本文来源 我爱IT技术网 http://www.52ij.com/jishu/5117.html 转载请保留链接。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
