```sql create or replace package body pkg_warning_sms is /** * 将预警短信从当前表迁移到历史表 **/ procedure sp_posp_warning_sms_move( i_ids in varchar2, -- 批量导入信息 o_flg out number -- 保存结果 ) is l_log varchar2(1000); l_sql varchar2(1000); begin -- 构建动态SQL并执行 l_sql := 'insert into posp_warning_sms_his (id, type, content, remark, warning_date) select p.id, p.type, p.content, p.remark, p.warning_date from posp_warning_sms p where p.id in (' || i_ids || ')'; execute immediate l_sql;
l_sql := 'delete from posp_warning_sms p where p.id in (' || i_ids || ')'; execute immediate l_sql; commit; o_flg := 1; exception when others then o_flg := 0; rollback; l_log := '迁移失败,错误代码: ' || sqlcode || ', 错误原因: ' || SUBSTR(SQLERRM, 1, 200); insert into posp_db_exec_log values ( TO_CHAR(SYSDATE, 'yyyymmdd') || LPAD(seq_posp_db_exec_log.NEXTVAL, 10, '0'), 'PKG_WARNING_SMS.SP_POSP_WARNING_SMS_MOVE', l_log, sysdate ); commit; RAISE; end; ```