注册 登录
编程论坛 Delphi论坛

急:在线等答案,有关DELPHI调用存储过程的一个问题

枫余风 发布于 2008-05-22 12:47, 860 次点击
rem *****************************************************
rem ** 产生进货单号过程
rem ** 功能:根据输入的年份,自动产生进货单编号
rem ** 输入参数:sYear 年份
rem ** 输出参数:returnGoods_in_ordinal 进货单编号
rem ******************************************************
CREATE or REPLACE PROCEDURE proGoods_in_ordinal (sYear varchar2,returnGoods_in_ordinal out varchar2)
is
  x number;                                 /*得到进货单编号后三位流水号*/
  varGoods_in_ordinal1 varchar2(9);         /*某年份的最大进货单编号*/
  varGoods_in_ordinal2 varchar2(9);         /*新的进货单编号*/
begin
  varGoods_in_ordinal1 :='';
  select NVL(max(in_ordinal),'0') into varGoods_in_ordinal1
  from Goods_in
  where in_ordinal like 'I'||sYear ||'%';
  if varGoods_in_ordinal1='0' then          /*没有该年份的进货单,编号从001开始*/
     varGoods_in_ordinal2 := 'I'||sYear || '-001';
  else
    x:= to_number(SUBSTR(varGoods_in_ordinal1,7,3))+1;
    if x<10 then varGoods_in_ordinal2 := 'I'||sYear || '-00' || ltrim(to_char(x));
    elsif x<100 then varGoods_in_ordinal2 := 'I'||sYear || '-0' || ltrim(to_char(x));
    else
        varGoods_in_ordinal2 := 'I'||sYear ||'-' || ltrim(to_char(x));
    end if;
  end if;
  returnGoods_in_ordinal := varGoods_in_ordinal2;
end proGoods_in_ordinal;
/

//自动产生进货单编号
procedure TfrmGoods_in.sbtnCreateGoods_inNoClick(Sender: TObject);
var sYear :string;
begin
  inherited;
  if trim(dbedtin_datetime.Text)='' then
  begin
    application.MessageBox('没有输入进货日期','提示',mb_ok);
    dbedtin_datetime.SetFocus;
    exit;
  end;
  sYear :=copy(trim(dbedtin_datetime.Text),1,4);  //获取进货的年份
  if astpGoods_inNo.Active then astpGoods_inNo.Close;
  astpGoods_inNo.Parameters.Clear;      //将存储过程的参数清空

  //调用存储过程的代码
  astpGoods_inNo.ProcedureName :='PROGOODS_IN_ORDINAL';
  astpGoods_inNo.Parameters.CreateParameter('SYEAR',ftString,pdInput,4,null);
  astpGoods_inNo.Parameters.CreateParameter('RETURNGOODS_IN_ORDINAL',
                                                   ftString,pdOutput,9,null);
  //设置参数
  astpGoods_inNo.Parameters.ParamByName('SYEAR').Value:=sYear;
  //执行存储过程
  try
    astpGoods_inNo.ExecProc;
    if atbGoods_in.State = dsBrowse then atbGoods_in.Edit;
    //atbGoods_in.FieldByName('in_ordinal').Value:=
      //               astpGoods_inNo.Parameters.ParamByName('Param1').Value;
    //过程调用
    atbGoods_in.FieldByName('In_ordinal').Value:=
        astpGoods_inNo.Parameters.ParamByName('RETURNGOODS_IN_ORDINAL').Value;
  except
    application.MessageBox(pchar('产生函数有错,请重试'),'提示',MB_OK);
    exit;
  end;
end;
运行DELPHI和存储过程都没有错,但是我希望显示出I2008-001,可运行后显示I2008-,这是为什么,等高人回答!
0 回复
1