create or replace procedure ys_sale_dts001
as
d_date date;
v_branchid varchar2(36);
BEGIN
 select to_date(to_char(SYSDATe -3,'yyyy-mm-dd'),'yyyy-mm-dd') into d_date  from dual;
 select branchid into v_branchid from ys_branch where branchcode='Y75614';
 delete from ys_sale_dts 
  where saleid in(select saleid from ys_sale where workdate=to_date('2012-10-17','yyyy-mm-dd')
   and branchid='E973F14A-1FE4-465D-A8F6-E3255C4D9607');
/* where saleid in(select saleid from ys_sale where workdate=d_date and branchid=v_branchid);*/
 insert into ys_sale_dts(saleid)
 select saleid from ys_sale where workdate=to_date('2012-10-17','yyyy-mm-dd')
   and branchid='E973F14A-1FE4-465D-A8F6-E3255C4D9607';commit;
END;

解决方案 »

  1.   

    saleid对应多个记录
    select saleid from ys_sale where rowid = 
    (select min(rowid) from ys_sale where workdate=to_date('2012-10-17','yyyy-mm-dd')
    and branchid='E973F14A-1FE4-465D-A8F6-E3255C4D9607');
      

  2.   

    create or replace procedure ys_sale_dts001
    as
    d_date date;
    v_branchid varchar2(36);
    BEGIN
     select to_date(to_char(SYSDATe -3,'yyyy-mm-dd'),'yyyy-mm-dd') into d_date from dual;
     select branchid into v_branchid from ys_branch where branchcode='Y75614';
     delete from ys_sale_dts  
      where saleid in(select saleid from ys_sale where workdate=to_date('2012-10-17','yyyy-mm-dd')
      and branchid='E973F14A-1FE4-465D-A8F6-E3255C4D9607');
    /* where saleid in(select saleid from ys_sale where workdate=d_date and branchid=v_branchid);*/
     insert into ys_sale_dts(saleid)
     select saleid from ys_sale where workdate=to_date('2012-10-17','yyyy-mm-dd')
      and branchid='E973F14A-1FE4-465D-A8F6-E3255C4D9607';commit;EXCEPTION WHEN   OTHERS 
                THEN 
                     DBMS_OUTPUT.PUTLINE(SQLERRM);   END;
    建议把错误信息输出来,更便于调试存储过程