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);
l_ids varchar2(1000);
begin
--将当前数据转移到历史表
l_ids := i_ids;
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 (' || l_ids || ')';
execute immediate l_sql;
l_sql := 'delete posp_warning_sms p where p.id in (' || l_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;
因为短信当前表和短信历史表的CONTENT的字段大小不一样。平时没什么,短信内容长些就无法转移到历史表中了! 为此报了错。
按道理报错后 被回滚。那么当前短信表该条短信内容是没被删除的。我去查短信内容长度应该能查到大于历史表300的短信。可惜没有!
那么会不会动态执行SQL 是独立的事物,默认提交?