declare
–定义变量时要声明类型
activity_defid varchar2(256);
–如果想得到一个结果集,在oracle中要使用游标,语法如下
cursor procInstId is select * from besorder.om_order where /business_code=‘CreateSubscriber’ and/ access_channel_type!=‘601’ and status=‘inProgress’ and create_time>sysdate-7 order by create_time desc;
begin
/*循环的结构:
for i in list loop
…
end loop;
*/
for i in procInstId loop
declare
j varchar2(250):=i.proc_inst_id;
begin
–将查询到的结果赋值给activity_defid
select activitydefid into activity_defid from(select * from besbpm.t_bpm_activitytrace t where t.processinstanceid=i.proc_inst_id order by t.execsequencenum desc) where rownum=1;
–IF判断的结构
if activity_defid like ‘%WaitCreateLogisticsOrderACK_callback_wait%’ then
dbms_output.put_line(‘1:orderId:’||i.order_id||’, businessCode:’||i.business_code||’, createTime:’||i.create_time||’!’);
elsif activity_defid like ‘%VerifyAndCreateSerialNumberAssignment_callback_wait%’ then
dbms_output.put_line(‘2:orderId:’||i.order_id||’, businessCode:’||i.business_code||’, createTime:’||i.create_time||’!’);
elsif activity_defid like ‘%WaitDeliveryACK1_callback_wait%’ then
dbms_output.put_line(‘3:orderId:’||i.order_id||’, businessCode:’||i.business_code||’, createTime:’||i.create_time||’!’);
elsif activity_defid like ‘%WaitDeliveryACKTemp1_callback_wait%’ then
dbms_output.put_line(‘3:orderId:’||i.order_id||’, businessCode:’||i.business_code||’, createTime:’||i.create_time||’!’);
elsif activity_defid like ‘%FuncWaitingAsignSerialNumberOpuTemp1_callback_wait%’ then
dbms_output.put_line(‘2:orderId:’||i.order_id||’, businessCode:’||i.business_code||’, createTime:’||i.create_time||’!’);
elsif activity_defid like ‘%FuncWaitLogisticsMessageStatusSetTemp2_callback_wait%’ then
dbms_output.put_line(‘1:orderId:’||i.order_id||’, businessCode:’||i.business_code||’, createTime:’||i.create_time||’!’);
end if;
–如果程序发生异常,一般在end之前添加异常处理
exception
when NO_DATA_FOUND/异常编码对应的名称/ then
DBMS_OUTPUT.PUT_LINE(‘程序运行错误!,异常订单ID:’||i.order_id||’.’);
continue;
end;
end loop;
end;
Oracle数据库编程获取异常订单
最新推荐文章于 2024-09-02 07:00:00 发布