给你一个例子: create or replace procedure GenFee( i_DepID Dept.ID%Type, /*要生成费用的科室*/ i_stf Staff.Id%Type /*o_result Out Number 0:正常结束*/ ) as /*名称: 生成费用 2003-6-4 wzp(过程间调用,无输出参数) 流程: 1取得整个病区的应该要收费的执行明细; 2循环每条明细。 3修改medorddtl的状态为已收费。 4插记录入patcost表。 调用到: function :genspprice; sp: GenActLog 涉及表: MedOrder,PatCost,MedOrdDtl,Patnow,fees,调试语句: execute GenFee(41,2),ok; */
v_docid Medorder.doc%Type; v_kind PatCost.feekd%Type; v_spprice PatCost.price%Type; cursor GenMedorddtl is /*待要生成费用的执行明细*/ select m.Ordid, m.patid, m.Feeid, m.todotm, m.depid, m.exedep, m.feenm, m.qty, p.bedchgid, f.price, f.invid, f.accid, f.stid from MedOrdDtl m, Patnow p, Fees f where m.depid = i_depid and m.isgat=0 and m.Feeid=f.id and m.patid=p.patid and ((m.iswas=0) or (m.iswas=1 and m.exedep=149 and m.dispid is not null) and f.IsRecycle=0) /*已经发消息到中心药房拿药的不可回收的明细也要计费*/ and m.todotm <=sysdate /*时间到目前为止*/ and m.exedep <>999 /*非自备药*/ order by ordid for update of m.isgat nowait; begin for c in GenMedorddtl loop /*修改medorddtl的状态为已收费*/ update MedOrdDtl set isgat =1 /*已收费*/ /* exeste =40 执行完毕*/ where current of GenMedOrdDtl ;
/*取得medorder表的信息为插入patcost用 */ select doc,kind into v_docid,v_kind from MedOrder where id=c.ordid ;
v_spprice := GenSpPrice(c.qty, c.price, c.feeid, c.depid ); if v_spprice =-1 then v_spprice :=c.price ; end if;
update MedOrdDtl set isgat =1 /*已收费*/ /* exeste =40 执行完毕*/ where current of GenMedOrdDtl ; --这里就是更新游标中MedOrdDtl表的记录集,where current of GenMedOrdDtl ;这句话是控制每一次检索出来的数据集进行更新,就是更新游标的一种方法
update tablename set money=(select money+value from others_table where id=oid);
create or replace procedure GenFee(
i_DepID Dept.ID%Type, /*要生成费用的科室*/
i_stf Staff.Id%Type
/*o_result Out Number 0:正常结束*/
) as
/*名称: 生成费用 2003-6-4 wzp(过程间调用,无输出参数)
流程:
1取得整个病区的应该要收费的执行明细;
2循环每条明细。
3修改medorddtl的状态为已收费。
4插记录入patcost表。
调用到:
function :genspprice; sp: GenActLog
涉及表:
MedOrder,PatCost,MedOrdDtl,Patnow,fees,调试语句: execute GenFee(41,2),ok;
*/
v_docid Medorder.doc%Type;
v_kind PatCost.feekd%Type;
v_spprice PatCost.price%Type;
cursor GenMedorddtl is /*待要生成费用的执行明细*/
select m.Ordid, m.patid, m.Feeid, m.todotm, m.depid, m.exedep, m.feenm, m.qty,
p.bedchgid, f.price, f.invid, f.accid, f.stid
from MedOrdDtl m, Patnow p, Fees f
where m.depid = i_depid
and m.isgat=0
and m.Feeid=f.id
and m.patid=p.patid
and ((m.iswas=0) or (m.iswas=1 and m.exedep=149 and m.dispid is not null) and f.IsRecycle=0)
/*已经发消息到中心药房拿药的不可回收的明细也要计费*/
and m.todotm <=sysdate /*时间到目前为止*/
and m.exedep <>999 /*非自备药*/
order by ordid
for update of m.isgat nowait; begin
for c in GenMedorddtl loop
/*修改medorddtl的状态为已收费*/
update MedOrdDtl
set isgat =1 /*已收费*/
/* exeste =40 执行完毕*/
where current of GenMedOrdDtl ;
/*取得medorder表的信息为插入patcost用 */
select doc,kind
into v_docid,v_kind
from MedOrder
where id=c.ordid ;
v_spprice := GenSpPrice(c.qty, c.price, c.feeid, c.depid );
if v_spprice =-1 then
v_spprice :=c.price ;
end if;
/*插记录入patcost表*/
insert into PatCost( COSTTM, COSTDATE, PATID, BEDCHGID, DEPID, ORDID, FEEID, FEENM, QTY, PRICE, SPCPRC,
DOCID, EXESTF, INVID, ACCID, STID, EXEDEP, FEEKD, CRTKD, BSNID )
values( c.todotm, sysdate,c.patid,c.bedchgid,c.depid,c.ordid,c.feeid,c.feenm,c.qty,c.price, v_spprice,
v_docid,i_stf,c.invid,c.accid,c.stid,c.exedep,v_kind,10,0 ) ;
end loop; /*结束未生成费用的执行明细的循环*/
/*o_result := 0 ; 正常结束*/
/*写日志*/
GenActLog(i_stf, '生成费用', 0,0,0,'Genfee- 生成病区费用');end;
/
set isgat =1 /*已收费*/
/* exeste =40 执行完毕*/
where current of GenMedOrdDtl ;
--这里就是更新游标中MedOrdDtl表的记录集,where current of GenMedOrdDtl ;这句话是控制每一次检索出来的数据集进行更新,就是更新游标的一种方法