失败2616计算期间发生数值溢出

时间:2019-12-30 06:46:49

标签: teradata numeric teradata-sql-assistant

尝试从长度为18的平面文件中插入记录时,bteq中的insert语句工作正常

INSERT INTO cust(online_customer)
SELECT 
  CASE 
    WHEN t1.site_id = 1002 THEN cast(t1.membership as DECIMAL(38,0))
    ELSE NULL
  END
FROM trans t1
LEFT OUTER JOIN cust1 t2 ON t1.membership = t2.membership AND t1.site_id = t2.site_id
;

但是当长度增加到19 im时,出现以下错误

 *** Failure 2616 Numeric overflow occurred during computation.
                Statement# 1, Info =0   
 *** Total elapsed time was 1 second.

online_customerDECIMAL(38,0)中,cust1被定义为membershipVARCHAR(40)被定义为transcust1表具有cust

1 个答案:

答案 0 :(得分:0)

这可能来自CASTINSERT。尝试分解查询,看看是哪个导致错误。

在查询中,您将VARCHAR(40)投射到DECIMAL(38,0),然后插入到VARCHAR(100)中。为什么不将VARCHAR插入VARCHAR并使用TO_NUMBER()来确保有效数字:

INSERT INTO cust(online_customer)
SELECT 
  CAST(
    CASE 
      WHEN t1.site_id = 1002 THEN TO_NUMBER(t1.membership) -- Ensure valid number
    END
    AS VARCHAR(100)
  )
FROM trans t1
LEFT OUTER JOIN cust1 t2 ON t1.membership = t2.membership AND t1.site_id = t2.site_id