oracle数据库存储过程的一个实例(运用到游标和循环)

自己写的一个存储过程实例(格式可以参照):
create or replace procedure comm.procedure_luguagua(patientId in varchar2,//入参
                                                    visitId   in number,
                                                    ldt_start in date,
                                                    ldt_end   in date,
                                                    isSuccess out number,//出参
                                                    errorInfo out varchar2) as
  name_temp          VARCHAR2(20);//存储过程的变量
  sex_temp           VARCHAR2(4);
  date_of_birth_temp date;
  charge_type_temp   varchar2(8);
  settling_date_temp date;
  subj_name_temp     varchar2(16);
  costs_temp         number(11, 4);
begin
  declare
   cursor mycursor is         //声明游标
    select b.name,
           b.sex,
           b.date_of_birth,
           b.charge_type,
           a.settling_date,
           c.subj_name,
           sum(a.costs)
      from inp_settle_master  a,
           pat_master_index   b,
           tally_subject_dict c,
           inp_bill_detail    d
     where a.patient_id = b.patient_id
       and a.patient_id = d.patient_id
       and a.visit_id = d.visit_id
       and d.subj_code = c.subj_code
       and a.patient_id = patientId
       and a.visit_id = visitId
       and a.transact_type = '正常'
       and a.settling_date between ldt_start and ldt_end
     group by b.name,
              b.sex,
              b.date_of_birth,
              b.charge_type,
              a.settling_date,
              c.subj_name;
   begin
     open mycursor;//打开游标
     loop
         fetch  mycursor into name_temp,sex_temp,date_of_birth_temp,charge_type_temp,settling_date_temp,subj_name_temp,costs_temp;
         if mycursor%found then //判断是否fetch值
            insert into comm.table_luguagua ( patient_id,visit_id,name,sex,date_of_birth,charge_type,settling_date, subj_name,costs)
                values ( patientId,visitId,name_temp,sex_temp,date_of_birth_temp,
                         charge_type_temp,settling_date_temp, subj_name_temp,costs_temp);
         end if;
         exit when mycursor%notfound; //判断是否提取完成
     end loop;
     close mycursor;//关闭游标
     isSuccess:= 1;
     errorInfo:= '';
     commit;
  end ;
  exception  //异常处理
    when NO_DATA_FOUND then
        isSuccess:=0;
        errorInfo:='no data found';
        rollback;
    when others then
        isSuccess:=0;
        errorInfo:='other error';
        rollback;
end procedure_luguagua;//结算存储过程


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值