IBM Support

SQL0802N might happen for SUM() function in specific SQL statements with DB2 V11.1

Troubleshooting


Problem

Db2 might return the error, "SQL0802N Arithmetic overflow or other arithmetic exception occurred. SQLSTATE=22003" while executing sum() function in V11.1 where it does not in V10.5.

Symptom


A SQL statement failed with SQL0802N Arithmetic overflow or other arithmetic exception occurred .
And the generated optimized statement was like the following example. It was different from the optimized statement with V10.5.

Example:

Original Statement:
------------------
SELECT ...

(SELECT SUM(T1.C1) FROM T1 WHERE T1.C2 = T2.C1)
...
(SELECT SUM(T1.C1) FROM T1 WHERE T1.C2 = T2.C1)
...
(SELECT SUM(T1.C1) FROM T1 WHERE T1.C2 = T2.C1)
...
) FROM T2

Nore:
The original statement has multiple subselect. They were rewritten to the following subselect using "group by".

Optimized Statement:
-------------------
SELECT ...

     (SELECT
        Q11.$C0
      FROM
        (SELECT
           SUM(Q10.C1),
           Q10."C2
         FROM
           (SELECT
              Q9.C1,
              Q9.C2
            FROM
              T1I AS Q9
           ) AS Q10
         GROUP BY
           Q10.C1
        ) AS Q11
      WHERE
        (Q11.C1 = Q8.C2)
     ) AS Q12

[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"--","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"11.1","Edition":"Advanced Enterprise Server;Advanced Workgroup Server;Enterprise Server;Express;Express-C;Personal;Workgroup Server","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Log InLog in to view more of this document

This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use Log in button above to access the full document. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.

Document Information

Modified date:
30 April 2025

UID

swg22011256