DB2 - Problembeschreibung
Problem IC73317 | Status: Geschlossen |
ASSIGNMENT OF PREDICATE TO BOOLEAN VARIABLE INSIDE OF AN IF-STATEMENT CAUSES SYNTAX ERROR. | |
Produkt: | |
DB2 FOR LUW / DB2FORLUW / 970 - DB2 | |
Problembeschreibung: | |
The assignment of a predicate to a boolean variable may result in a syntax error, SQL0104N, when all of the following conditions are met: - An SQL procedure, compiled SQL function, or compiled trigger contains an IF statement; - Each THEN, ELSE IF, or ELSE clause in the IF statement contains an assignment to the same Boolean variable, and no other statements; - The right-hand side of at least one of the assignment statements is a predicate. Example (PL/SQL, DB2_COMPATIBILITY_VECTOR=ORA): declare b boolean; m varchar2(1); begin IF m = 'A' THEN b := m = 'A'; ELSE b := false; end if; end@ which results in an error similar to the following: SQL0104N An unexpected token "=" was found following "N :HV00009 :HI00009". Expected tokens may include: "CONCAT". LINE NUMBER=1. SQLSTATE=42601 The equivalent DB2 SQL PL example is: begin declare b boolean; declare m varchar(1); if m = 'A' then set b = m = 'A'; end if; end@ | |
Problem-Zusammenfassung: | |
**************************************************************** * USERS AFFECTED: * * ALL * **************************************************************** * PROBLEM DESCRIPTION: * * The assignment of a predicate to a boolean variable may * * result * * in a syntax error, SQL0104N, when all of the following * * * * conditions * * * * are met: * * * * * * * * - An SQL procedure, compiled SQL function, or compiled * * trigger * * contains an IF statement; * * * * - Each THEN, ELSE IF, or ELSE clause in the IF statement * * * * contains an assignment to the same Boolean variable, and no * * * * other * * * * statements; * * * * - The right-hand side of at least one of the assignment * * * * statements is a predicate. * * * * * * * * Example (PL/SQL, DB2_COMPATIBILITY_VECTOR=ORA): * * * * * * * * declare * * * * b boolean; * * * * m varchar2(1); * * * * begin * * * * IF m = 'A' THEN * * * * b := m = 'A'; * * * * ELSE * * * * b := false; * * * * end if; * * * * end@ * * * * * * * * which results in an error similar to the following: * * * * * * * * SQL0104N An unexpected token "=" was found following "N * * * * :HV00009 :HI00009". * * * * * * * * Expected tokens may include: "CONCAT". LINE NUMBER=1. * * * * SQLSTATE=42601 * * * * * * * * The equivalent DB2 SQL PL example is: * * * * * * * * begin * * * * declare b boolean; * * * * declare m varchar(1); * * * * * * * * if m = 'A' then * * * * set b = m = 'A'; * * * * end if; * * * * end@ * **************************************************************** * RECOMMENDATION: * * Upgrade to DB2 Version 9.7 Fix Pack 5. * **************************************************************** | |
Local-Fix: | |
As a workaround, if you have an assignment with a boolean-valued expression inside an IF statement, insert a NULL statement (PL/SQL) or an empty compound statement (SQL PL) immediately before or after the assignment. For the PL/SQL case given in the error description: declare b boolean; m varchar2(1); begin IF m = 'A' THEN null; -- workaround b := m = 'A'; end if; end@ In DB2 SQL PL, the equivalent workaround is: begin declare b boolean; declare m varchar(1); if m = 'A' then begin end; -- workaround set b = m = 'A'; end if; end@ | |
verfügbare FixPacks: | |
DB2 Version 9.7 Fix Pack 5 for Linux, UNIX, and Windows | |
Lösung | |
This problem will be fixed in DB2 Version 9.7 Fix Pack 5. | |
Workaround | |
keiner bekannt / siehe Local-Fix | |
Weitere Daten | |
Datum - Problem gemeldet : Datum - Problem geschlossen : Datum - der letzten Änderung: | 16.12.2010 07.12.2011 07.12.2011 |
Problem behoben ab folgender Versionen (IBM BugInfos) | |
9.7.FP5 | |
Problem behoben lt. FixList in der Version | |
9.7.0.5 |