create or replace trigger t_insert_import_order
before insert on wms_import_order
for each row
declare
-- local variables here
v_today varchar2(10);
v_max_no varchar2(20);
v_xw number;
begin
-- select seq_rklsd.nextval into :new.IMPORT_ORDER_NO from dual;
select max(import_order_no) into v_max_no from wms_import_order;
select to_char(sysdate,'yyyymmdd') into v_today from dual;
if v_max_no is null or substr(v_max_no,3,8)<>v_today then
:new.import_order_no:='RK'||v_today||'000001';
else
:new.import_order_no:=substr(v_max_no,1,10)||trim(to_char(to_number(substr(v_max_no,11))+1,'000000'));
end if;
select count(*) into v_xw from wms_import_order where import_stock_code = :new.import_stock_code and import_execute_flag in ('0','1');
if v_xw >0 then
:new.import_execute_flag:='3';
end if;
end t_insert_import_order;
/
老子实在没什么可发 又不想复制你们的段子 哎