oracle存储过程带游标例子
create or replace procedure p_tmpbegin declare cursor c_cur is select st.business_id as business_id, st.userid as userid, st.end_date as end_date, st.creation_date as creation_date from tableH st where 1=1; v_row c_cur%rowtype; v_business_id_t varchar2(200); begin open c_cur; loop fetch c_cur into v_row; exit when c_cur%notfound; select count(n.business_id) into v_business_id_t from tableM n where n.business_id = v_row.business_id and n.userid = v_row.userid; if v_business_id_t = 0 then insert into tableN (business_id, userid, end_date, creation_date) values (v_row.business_id, v_row.userid, v_row.end_date, v_row.creation_date); end if; if v_business_id_t > 0 then update tableN t set t.end_date = v_row.end_date where t.business_id = v_row.business_id and t.userid = v_row.userid; end if; end loop; close c_cur; commit; end;exception when others then rollback; dbms_output.put_line('异常啦');end;