The standard only permits UNION outside of subqueries in DECLARE CURSOR Explanation: You have included a UNION in a context in which the ANSI and ISO SQL standards do not support. Only DECLARE CURSOR statements may have a UNION in the standard. User Action: If it is important to have only standard features in your program, you should remove this UNION clause.