出生日期变更记录添加存储过程.sqlcreate or replace procedure update_birthday_his(i_rfid in varchar2)
出生日期变更记录添加存储过程.sql
create or replace procedure update_birthday_his(i_rfid in varchar2) isv_birthdayLast date;v_birthday date;v_updateTime date;v_result varchar2(2048);cursor r isselect h.birthday as birthday, case when h.update_time is null then h.his_time else h.update_time end as updateTime from his_animal_info hwhere h.birthday is not null and h.rfid = i_rfidorder by h.update_time;thedata r%rowtype;begin open r; loop fetch r into thedata; exit when r%notfound; v_birthday := thedata.birthday; v_updateTime := thedata.updateTime; if(v_birthday <> v_birthdayLast) then v_result := v_result||to_char(v_updateTime,'yyyy-mm-dd hh24:mi:ss')||chr(10)||' --> '||to_char(v_birthday,'yyyy-mm-dd')||chr(10);/*字符串中换行用chr(10)*/ end if; v_birthdayLast := v_birthday; end loop; update tbl_animal_info a set a.birthday_his = v_result where a.rfid = i_rfid; commit;end;
