算术溢出错误-802

时间:2014-09-10 06:34:48

标签: sql

你有一个表来获取来自一个过程的数据,该过程工作正常但是当试图插入该数据时我得到一个算术错误,我不知道你是如何解决这个问题的。任何帮助,将不胜感激。

这是程序:

SET TERM ^ ;
CREATE PROCEDURE REPORT_CONTROLLEDGER (
  DATESTART Date,
  DATEEND Date,
  INCOMPANYID Integer )
RETURNS (
  GLCODE Varchar(8),
  DATUM Date,
  PERIOD Varchar(2),
  SOURCE Varchar(30),
  REFERENCENO Varchar(200),
  GLDESCRIPTION Varchar(200),
  DESCRIPTION Varchar(1000),
  DR Numeric(10,2),
  CR Numeric(10,2),
  COSTCODE Varchar(8),
  BALANCE Numeric(10,2),
  COMPANYID Integer )
AS
  declare lastglcode varchar (8);
  declare grouptype integer;
  declare tglcode varchar (8);
  declare tdatum date;
  declare tperiod varchar (2);
  declare tsource varchar (30);
  declare treferenceno varchar (200);
  declare tdescription varchar (1000);
  declare tdr numeric (10,2);
  declare tcr numeric (10,2);
  declare tcostcode varchar (8);


begin
  lastglcode = '';
  balance = 0;
  companyid = incompanyid;
  for select glcode, datum, period, source, referenceno, description, dr, cr, costcode from controlledger where companyid = :companyid and datum between :datestart and :dateend order by GLCODE, datum, id  
  into tglcode, tdatum, tperiod, tsource, treferenceno, tdescription, tdr, tcr, tcostcode  
do
begin
  select description from subcode where glcode = :tglcode and companyid = :companyid into :gldescription;
  if (lastglcode <> tglcode) then
  begin
    select grouptype from subcode where glcode = :tglcode and companyid = :companyid into :grouptype;

  if (grouptype = 1) then
  begin
    select sum (dr - cr) from CONTROLLEDGER where companyid = :companyid and glcode = :tglcode and datum < :datestart into :balance;  
    if (balance is null) then balance = 0;
    glcode = tglcode;
    referenceno = null;
    description = 'Balance Brought Forward';
    cr = null;
    dr = null;
    source = null;
    costcode = null;
    datum = null;
    period = null; -- added by Andre
    suspend;  

  end 
    else
  begin
    balance = 0;
  end 
  lastglcode = tglcode; 
end
glcode = tglcode;
referenceno = treferenceno;
description = tdescription;
cr = tcr;
dr = tdr;
source = tsource;
costcode = tcostcode;
datum = tdatum;
period = tperiod; -- added by Andre

balance = balance + (tdr - tcr);   
suspend;
end

end^
SET TERM ; ^

GRANT EXECUTE
 ON PROCEDURE REPORT_CONTROLLEDGER TO  SYSDBA;

这里是insert语句:

insert into tblreport_ledgercontrol select cast('03/01/2013' as date),
             cast('04/30/2014' as date),
             iif(cl.DATUM is null, 'now', cl.DATUM)as datum,
             'Detailed Ledger Report from 0000.000 to 9999.999 for period 01/03/2013 to 30/04/2014' as reporttitle,
               'ubuntu' as processedby,
                iif(cl.GLCODE is null, 00, cl.GLCODE)as glcode,
                iif(cl.PERIOD is null, 0 , cl.PERIOD)as period,
                iif(cl.SOURCE is null, 'n/a', cl.SOURCE)as source,
                iif(cl.REFERENCENO is null, 'n/a', cl.REFERENCENO)as referenceno,
                cl.GLDESCRIPTION,
                cl.DESCRIPTION,
                iif(cl.dr is null, 0, cl.dr)as dr,
                iif(cl.cr is null, 0, cl.cr)as cr,
                iif(cl.COSTCODE is null, 00, cl.COSTCODE)as costcode,
                cl.BALANCE,
                cl.COMPANYID,
                955,
                gen_id (GEN_TBLREPORT_LEDGERCONTROL_ID, 1)
        from report_controlledger ('03/01/2013','04/30/2014', 676) cl

2 个答案:

答案 0 :(得分:0)

我相信数字溢出意味着你试图将5位数字放入4位数字段。 (即:不能将12345插入数字(4,0)列)

答案 1 :(得分:0)

感谢您的投入,您与错误相去甚远。 该过程允许描述为varchar(1000),而它插入的表允许描述为varchar(200),这导致溢出错误。

这里的灵魂是将目标表中的desciption字段更改为blob,或者使用alter语句增加描述的char大小以匹配过程的char大小。

firebird sql:

alter table TBLREPORT_LEDGERCONTROL alter description type varchar(1000)